drm/panthor: Fix IO-page mmap() for 32-bit userspace on 64-bit kernel
Subsystems (3)
Boris Brezillon
maintainerPATCH v2 1/3 drm/panthor: Fix IO-page mmap() for 32-bit userspace on 64-bit kernel
When mapping an IO region, the pseudo-file offset is dependent on the userspace architecture. panthor_device_mmio_offset() abstracts that away for us by turning a userspace MMIO offset into its kernel equivalent, but we were not updating vm_area_struct::vm_pgoff accordingly, leading us to attach the MMIO region to the wrong file offset.
This has implications when we start mixing 64 bit and 32 bit apps, but that's only really a problem when we start having more that 2^43 bytes of memory allocated, which is very unlikely to happen.
What's more problematic is the fact this turns our unmap_mapping_range(DRM_PANTHOR_USER_MMIO_OFFSET) calls, which are supposed to kill the MMIO mapping when entering suspend, into NOPs. Which means we either keep the dummy flush_id mapping active at all times, or we risk a BUS_FAULT if the MMIO region was mapped, and the GPU is suspended after that.
Solve that by patching vm_pgoff early in panthor_mmap(). With this in place, we no longer need the panthor_device_mmio_offset() helper.
v2:
- Kill panthor_device_mmio_offset()
--- drivers/gpu/drm/panthor/panthor_device.c | 8 ++++---- drivers/gpu/drm/panthor/panthor_device.h | 24 ------------------------ drivers/gpu/drm/panthor/panthor_drv.c | 17 ++++++++++++++++- 3 files changed, 20 insertions(+), 29 deletions(-)
drivers/gpu/drm/panthor/panthor_device.c +4 -4
@@ -334,7 +334,7 @@ static vm_fault_t panthor_mmio_vm_fault(struct vm_fault *vmf) {struct vm_area_struct *vma = vmf->vma;struct panthor_device *ptdev = vma->vm_private_data; -u64 id = (u64 )vma->vm_pgoff <<PAGE_SHIFT ; +u64 offset = (u64 )vma->vm_pgoff <<PAGE_SHIFT ;unsigned long pfn;pgprot_t pgprot;vm_fault_t ret;
@@ -347,7 +347,7 @@ static vm_fault_t panthor_mmio_vm_fault(struct vm_fault *vmf)mutex_lock (&ptdev->pm.mmio_lock); active =atomic_read (&ptdev->pm.state) ==PANTHOR_DEVICE_PM_STATE_ACTIVE ; -switch (panthor_device_mmio_offset (id)) { +switch (offset) {case DRM_PANTHOR_USER_FLUSH_ID_MMIO_OFFSET :if (active) pfn =__phys_to_pfn (ptdev->phys_addr +CSF_GPU_LATEST_FLUSH_ID );
@@ -378,9 +378,9 @@ static const struct vm_operations_struct panthor_mmio_vm_ops = {int panthor_device_mmap_io (struct panthor_device *ptdev,struct vm_area_struct *vma) { -u64 id = (u64 )vma->vm_pgoff <<PAGE_SHIFT ; +u64 offset = (u64 )vma->vm_pgoff <<PAGE_SHIFT ; -switch (panthor_device_mmio_offset (id)) { +switch (offset) {case DRM_PANTHOR_USER_FLUSH_ID_MMIO_OFFSET :if (vma->vm_end - vma->vm_start !=PAGE_SIZE || (vma->vm_flags & (VM_WRITE |VM_EXEC )))
drivers/gpu/drm/panthor/panthor_device.h +0 -24
@@ -365,30 +365,6 @@ static int panthor_request_ ## __name ## _irq(struct panthor_device *ptdev, \ pirq); \ } -/** -* panthor_device_mmio_offset() - Turn a user MMIO offset into a kernel one -* @offset: Offset to convert. -* -* With 32-bit systems being limited by the 32-bit representation of mmap2's -* pgoffset field, we need to make the MMIO offset arch specific. This function -* converts a user MMIO offset into something the kernel driver understands. -* -* If the kernel and userspace architecture match, the offset is unchanged. If -* the kernel is 64-bit and userspace is 32-bit, the offset is adjusted to match -* 64-bit offsets. 32-bit kernel with 64-bit userspace is impossible. -* -* Return: Adjusted offset. -*/ -static inline u64 panthor_device_mmio_offset (u64 offset) -{ -#ifdef CONFIG_ARM64 -if (test_tsk_thread_flag (current,TIF_32BIT )) - offset +=DRM_PANTHOR_USER_MMIO_OFFSET_64BIT -DRM_PANTHOR_USER_MMIO_OFFSET_32BIT ; -#endif - -return offset; -} -extern struct workqueue_struct *panthor_cleanup_wq;#endif
drivers/gpu/drm/panthor/panthor_drv.c +16 -1
@@ -1327,7 +1327,22 @@ static int panthor_mmap(struct file *filp, struct vm_area_struct *vma)if (!drm_dev_enter (file->minor->dev, &cookie))return -ENODEV ; -if (panthor_device_mmio_offset (offset) >=DRM_PANTHOR_USER_MMIO_OFFSET ) +#ifdef CONFIG_ARM64 +/* +* With 32-bit systems being limited by the 32-bit representation of +* mmap2's pgoffset field, we need to make the MMIO offset arch +* specific. This converts a user MMIO offset into something the kernel +* driver understands. +*/ +if (test_tsk_thread_flag (current,TIF_32BIT ) && + offset >=DRM_PANTHOR_USER_MMIO_OFFSET_32BIT ) { + offset +=DRM_PANTHOR_USER_MMIO_OFFSET_64BIT - +DRM_PANTHOR_USER_MMIO_OFFSET_32BIT ; + vma->vm_pgoff = offset >>PAGE_SHIFT ; + } +#endif + +if (offset >=DRM_PANTHOR_USER_MMIO_OFFSET ) ret =panthor_device_mmap_io (ptdev, vma);else ret =drm_gem_mmap (filp, vma);
Signature · 1 line
2.44.0
Boris Brezillon
maintainerPATCH v2 2/3 drm/panthor: Fix ordering in _irq_suspend()
Make sure we set suspended=true last to avoid generating an irq storm in the unlikely case where an IRQ happens between the suspended=true assignment and the _INT_MASK update.
v2:
- New patch
--- drivers/gpu/drm/panthor/panthor_device.h | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-)
drivers/gpu/drm/panthor/panthor_device.h +2 -2
@@ -325,7 +325,7 @@ static inline void panthor_ ## __name ## _irq_suspend(struct panthor_irq *pirq) { \int cookie; \ \ -atomic_set (&pirq->suspended, true); \ + pirq->mask =0 ; \ \if (drm_dev_enter (&pirq->ptdev->base, &cookie)) { \ gpu_write(pirq->ptdev, __reg_prefix ## _INT_MASK, 0); \
@@ -333,7 +333,7 @@ static inline void panthor_ ## __name ## _irq_suspend(struct panthor_irq *pirq)drm_dev_exit (cookie); \ } \ \ - pirq->mask =0 ; \ +atomic_set (&pirq->suspended, true); \ } \ \ static inline void panthor_ ## __name ## _irq_resume(struct panthor_irq *pirq, u32 mask) \
Signature · 1 line
2.44.0
Re: [PATCH v2 2/3] drm/panthor: Fix ordering in _irq_suspend()
Quoted 9 lines · Boris Brezillon
Make sure we set suspended=true last to avoid generating an irq storm in the unlikely case where an IRQ happens between the suspended=true assignment and the
_INT_MASKupdate.v2:
- New patchReported-by Steven Price <[email protected]>Signed-off-by Boris Brezillon <[email protected]>
Thanks!
Steve
Quoted 26 lines
--- drivers/gpu/drm/panthor/panthor_device.h | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-)drivers/gpu/drm/panthor/panthor_device.h +2
-2@@ -325,7 +325,7 @@ static inline void panthor_ ## __name ## _irq_suspend(struct panthor_irq *pirq) { \int cookie; \ \ -atomic_set (&pirq->suspended, true); \ + pirq->mask =0 ; \ \if (drm_dev_enter (&pirq->ptdev->base, &cookie)) { \ gpu_write(pirq->ptdev, __reg_prefix ## _INT_MASK, 0); \@@ -333,7 +333,7 @@ static inline void panthor_ ## __name ## _irq_suspend(struct panthor_irq *pirq)drm_dev_exit (cookie); \ } \ \ - pirq->mask =0 ; \ +atomic_set (&pirq->suspended, true); \ } \ \ static inline void panthor_ ## __name ## _irq_resume(struct panthor_irq *pirq, u32 mask) \
Liviu Dudau
maintainerRe: [PATCH v2 2/3] drm/panthor: Fix ordering in _irq_suspend()
In reply to Boris BrezillonQuoted 18 lines · Boris Brezillon
Make sure we set suspended=true last to avoid generating an irq storm in the unlikely case where an IRQ happens between the suspended=true assignment and the
_INT_MASKupdate.v2:
- New patchReported-by Steven Price <[email protected]>Signed-off-by Boris Brezillon <[email protected]>--- drivers/gpu/drm/panthor/panthor_device.h | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-)drivers/gpu/drm/panthor/panthor_device.h +0
-0
drivers/gpu/drm/panthor/panthor_device.h static inline void panthor_ ## __name ## _irq_suspend(struct panthor_irq *pirq) · line 328
Quoted 5 lines
drivers/gpu/drm/panthor/panthor_device.h +1
-1@@ -325,7 +325,7 @@ static inline void panthor_ ## __name ## _irq_suspend(struct panthor_irq *pirq) { \int cookie; \ \ -atomic_set (&pirq->suspended, true); \ + pirq->mask =0 ; \
I think you might still have a race between _irq_suspend() and _irq_threaded_handler() where the status will be zero due to pirq->mask being zero, so no interrupt will be cleared but they will be masked (kind of the opposite problem to patch 3/3).
I'm starting to think that pirq->mask should be local to _irq_threaded_handler() and not be messed with in the other functions.
drivers/gpu/drm/panthor/panthor_device.h static inline void panthor_ ## __name ## _irq_suspend(struct panthor_irq *pirq) · line 331
Quoted 3 lines
drivers/gpu/drm/panthor/panthor_device.h +0
-0\if (drm_dev_enter (&pirq->ptdev->base, &cookie)) { \ gpu_write(pirq->ptdev, __reg_prefix ## _INT_MASK, 0); \
If you move the line above before the if condition, do you still need patch 3/3?
Best regards,
Liviu
Quoted 12 lines
drivers/gpu/drm/panthor/panthor_device.h +1
-1@@ -333,7 +333,7 @@ static inline void panthor_ ## __name ## _irq_suspend(struct panthor_irq *pirq)drm_dev_exit (cookie); \ } \ \ - pirq->mask =0 ; \ +atomic_set (&pirq->suspended, true); \ } \ \ static inline void panthor_ ## __name ## _irq_resume(struct panthor_irq *pirq, u32 mask) \Signature · 1 line
2.44.0
Signature · 8 lines
====================
| I would like to |
| fix the world, |
| but they're not |
| giving me the |
\ source code! /
---------------
¯\_(ツ)_/¯Boris Brezillon
maintainerRe: [PATCH v2 2/3] drm/panthor: Fix ordering in _irq_suspend()
Quoted 14 lines · On Mon, 25 Mar 2024 17:16:16 +0000 Liviu Dudau <[email protected]> wrote:
Quoted 13 lines · Boris Brezillon
Make sure we set suspended=true last to avoid generating an irq storm in the unlikely case where an IRQ happens between the suspended=true assignment and the
_INT_MASKupdate.v2:
- New patchReported-by Steven Price <[email protected]>Signed-off-by Boris Brezillon <[email protected]>--- drivers/gpu/drm/panthor/panthor_device.h | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-)
Quoted 14 lines
drivers/gpu/drm/panthor/panthor_device.h static inline void panthor_ ## __name ## _irq_suspend(struct panthor_irq *pirq) · line 328
Quoted 10 lines
drivers/gpu/drm/panthor/panthor_device.h +1
-1@@ -325,7 +325,7 @@ static inline void panthor_ ## __name ## _irq_suspend(struct panthor_irq *pirq) { \int cookie; \ \ -atomic_set (&pirq->suspended, true); \ + pirq->mask = 0; \I think you might still have a race between
_irq_suspend()and_irq_threaded_handler()where the status will be zero due topirq->maskbeing zero, so no interrupt will be cleared but they will be masked (kind of the opposite problem to patch 3/3).
Right, but I'm trying to find a case where this is an issue. Yes, we might lose events, but at the same time, when _irq_suspend() is called, we are supposed to be idle, so all this mask=0 assignment does is speed-up the synchronization with the irq-thread. If there's anything we need to be done before suspending the IRQ, this should really use its own synchronization model.
Quoted 3 lines
I'm starting to think that
pirq->maskshould be local to_irq_threaded_handler()and not be messed with in the other functions.
It kinda is, as we don't modify panthor_irq::mask outside the suspend/resume (and now unplug) path, and each of these accesses has a reason to exist:
- in the resume path, we know all IRQs are masked, and we reset the SW-side mask to the interrupts we want to accept before updating _INT_MASK. No risk of race in that one
- in the unplug path, I don't think we care about unhandled interrupts, because the device will become unusable after that point, so updating the panthor_irq::mask early and losing events should be okay.
- the suspend case has been described above. As explained, I don't think it matters if we lose events there, because really, if there's any synchronization needed, it should have happened explicitly before _irq_suspend() is called. The synchronize_irq() we have is just here to make sure there's nothing accessing registers when we turn the device clk/power-domain off.
Quoted 6 lines
drivers/gpu/drm/panthor/panthor_device.h static inline void panthor_ ## __name ## _irq_suspend(struct panthor_irq *pirq) · line 331
Quoted 4 lines
drivers/gpu/drm/panthor/panthor_device.h +0
-0\if (drm_dev_enter (&pirq->ptdev->base, &cookie)) { \ gpu_write(pirq->ptdev, __reg_prefix ## _INT_MASK, 0); \If you move the line above before the if condition, do you still need patch 3/3?
The whole point of the drm_dev_enter/exit() section was to prevent access to registers after the device has been unplugged, so, if I move the gpu_write() outside of this block, I'd rather drop the entire drm_dev_enter/exit() section (both here and in _irq_resume()). That should be safe actually, as I don't expect the PM hooks or the reset handler to be called after the device and its resource have been removed, and those are the two only paths where _irq_suspend/resume() can be called.
Liviu Dudau
maintainerRe: [PATCH v2 2/3] drm/panthor: Fix ordering in _irq_suspend()
Quoted 32 lines · Boris Brezillon
Quoted 14 lines · On Mon, 25 Mar 2024 17:16:16 +0000 Liviu Dudau <[email protected]> wrote:
Quoted 13 lines · Boris Brezillon
Make sure we set suspended=true last to avoid generating an irq storm in the unlikely case where an IRQ happens between the suspended=true assignment and the
_INT_MASKupdate.v2:
- New patchReported-by Steven Price <[email protected]>Signed-off-by Boris Brezillon <[email protected]>--- drivers/gpu/drm/panthor/panthor_device.h | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-)Quoted 14 lines
drivers/gpu/drm/panthor/panthor_device.h static inline void panthor_ ## __name ## _irq_suspend(struct panthor_irq *pirq) · line 328
Quoted 10 lines
drivers/gpu/drm/panthor/panthor_device.h +1
-1@@ -325,7 +325,7 @@ static inline void panthor_ ## __name ## _irq_suspend(struct panthor_irq *pirq) { \int cookie; \ \ -atomic_set (&pirq->suspended, true); \ + pirq->mask = 0; \I think you might still have a race between
_irq_suspend()and_irq_threaded_handler()where the status will be zero due topirq->maskbeing zero, so no interrupt will be cleared but they will be masked (kind of the opposite problem to patch 3/3).
Quoted 6 lines
Right, but I'm trying to find a case where this is an issue. Yes, we might lose events, but at the same time, when
_irq_suspend()is called, we are supposed to be idle, so all this mask=0 assignment does is speed-up the synchronization with the irq-thread. If there's anything we need to be done before suspending the IRQ, this should really use its own synchronization model.
Perf counter collection before going idle ;)
I know that's not yet on your radar, but we need to keep it in mind to test that scenario when we add support for keeping runtime PM alive during perf counters dumping.
Quoted 29 lines
Quoted 4 lines
I'm starting to think that
pirq->maskshould be local to_irq_threaded_handler()and not be messed with in the other functions.It kinda is, as we don't modify
panthor_irq::maskoutside the suspend/resume (and now unplug) path, and each of these accesses has a reason to exist:- in the resume path, we know all IRQs are masked, and we reset the SW-side mask to the interrupts we want to accept before updating
_INT_MASK. No risk of race in that one
- in the unplug path, I don't think we care about unhandled interrupts, because the device will become unusable after that point, so updating thepanthor_irq::maskearly and losing events should be okay.
- the suspend case has been described above. As explained, I don't think it matters if we lose events there, because really, if there's any synchronization needed, it should have happened explicitly before_irq_suspend()is called. Thesynchronize_irq()we have is just here to make sure there's nothing accessing registers when we turn the device clk/power-domain off.Quoted 6 lines
drivers/gpu/drm/panthor/panthor_device.h static inline void panthor_ ## __name ## _irq_suspend(struct panthor_irq *pirq) · line 331
Quoted 4 lines
drivers/gpu/drm/panthor/panthor_device.h +0
-0\if (drm_dev_enter (&pirq->ptdev->base, &cookie)) { \ gpu_write(pirq->ptdev, __reg_prefix ## _INT_MASK, 0); \If you move the line above before the if condition, do you still need patch 3/3?
Quoted 8 lines
The whole point of the drm_dev_enter/exit() section was to prevent access to registers after the device has been unplugged, so, if I move the
gpu_write()outside of this block, I'd rather drop the entire drm_dev_enter/exit() section (both here and in_irq_resume()). That should be safe actually, as I don't expect the PM hooks or the reset handler to be called after the device and its resource have been removed, and those are the two only paths where _irq_suspend/resume() can be called.
Agree. It feels strange to care a lot about preventing access to registers (as we should) and then going and adding the unplug function which replaces the suspend in 3 out of 7 cases. New contributors might get confused about which one to use in the future.
What we should do is rename suspend to unplug and move the drm_dev_enter/exit() condition at the calling point for the cases where it makes sense.
Best regards,
Liviu
Signature · 8 lines
====================
| I would like to |
| fix the world, |
| but they're not |
| giving me the |
\ source code! /
---------------
¯\_(ツ)_/¯Boris Brezillon
maintainerRe: [PATCH v2 2/3] drm/panthor: Fix ordering in _irq_suspend()
Quoted 33 lines · On Tue, 26 Mar 2024 09:58:17 +0000 Liviu Dudau <[email protected]> wrote:
Quoted 32 lines · Boris Brezillon
Quoted 28 lines · On Mon, 25 Mar 2024 17:16:16 +0000 Liviu Dudau <[email protected]> wrote:
Quoted 18 lines · Boris Brezillon
Make sure we set suspended=true last to avoid generating an irq storm in the unlikely case where an IRQ happens between the suspended=true assignment and the
_INT_MASKupdate.v2:
- New patchReported-by Steven Price <[email protected]>Signed-off-by Boris Brezillon <[email protected]>--- drivers/gpu/drm/panthor/panthor_device.h | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-)drivers/gpu/drm/panthor/panthor_device.h +0
-0drivers/gpu/drm/panthor/panthor_device.h static inline void panthor_ ## __name ## _irq_suspend(struct panthor_irq *pirq) · line 328
Quoted 5 lines
drivers/gpu/drm/panthor/panthor_device.h +1
-1@@ -325,7 +325,7 @@ static inline void panthor_ ## __name ## _irq_suspend(struct panthor_irq *pirq) { \int cookie; \ \ -atomic_set (&pirq->suspended, true); \ + pirq->mask = 0; \I think you might still have a race between
_irq_suspend()and_irq_threaded_handler()where the status will be zero due topirq->maskbeing zero, so no interrupt will be cleared but they will be masked (kind of the opposite problem to patch 3/3).
Quoted 8 lines
Quoted 6 lines
Right, but I'm trying to find a case where this is an issue. Yes, we might lose events, but at the same time, when
_irq_suspend()is called, we are supposed to be idle, so all this mask=0 assignment does is speed-up the synchronization with the irq-thread. If there's anything we need to be done before suspending the IRQ, this should really use its own synchronization model.Perf counter collection before going idle ;)
That's typically a case of synchronization that should be done explicitly rather than relying on the synchronize_irq() we have in _irq_suspend().
Quoted 4 lines
I know that's not yet on your radar, but we need to keep it in mind to test that scenario when we add support for keeping runtime PM alive during perf counters dumping.
It's definitely on our radar, but I don't think _irq_suspend() is the right way to handle perfcnt dump synchronization. IMHO, it deserves its own _perfcnt_suspend() function that's called before _fw_suspend() to make sure any in-flight perfcnt dumps get flushed before the JOB/FW irq suspend happens.
Quoted 39 lines
Quoted 30 lines
Quoted 5 lines
I'm starting to think that
pirq->maskshould be local to_irq_threaded_handler()and not be messed with in the other functions.It kinda is, as we don't modify
panthor_irq::maskoutside the suspend/resume (and now unplug) path, and each of these accesses has a reason to exist:- in the resume path, we know all IRQs are masked, and we reset the SW-side mask to the interrupts we want to accept before updating
_INT_MASK. No risk of race in that one
- in the unplug path, I don't think we care about unhandled interrupts, because the device will become unusable after that point, so updating thepanthor_irq::maskearly and losing events should be okay.
- the suspend case has been described above. As explained, I don't think it matters if we lose events there, because really, if there's any synchronization needed, it should have happened explicitly before_irq_suspend()is called. Thesynchronize_irq()we have is just here to make sure there's nothing accessing registers when we turn the device clk/power-domain off.Quoted 6 lines
drivers/gpu/drm/panthor/panthor_device.h static inline void panthor_ ## __name ## _irq_suspend(struct panthor_irq *pirq) · line 331
Quoted 4 lines
drivers/gpu/drm/panthor/panthor_device.h +0
-0\if (drm_dev_enter (&pirq->ptdev->base, &cookie)) { \ gpu_write(pirq->ptdev, __reg_prefix ## _INT_MASK, 0); \If you move the line above before the if condition, do you still need patch 3/3?
Quoted 8 lines
The whole point of the drm_dev_enter/exit() section was to prevent access to registers after the device has been unplugged, so, if I move the
gpu_write()outside of this block, I'd rather drop the entire drm_dev_enter/exit() section (both here and in_irq_resume()). That should be safe actually, as I don't expect the PM hooks or the reset handler to be called after the device and its resource have been removed, and those are the two only paths where _irq_suspend/resume() can be called.
Quoted 4 lines
Agree. It feels strange to care a lot about preventing access to registers (as we should) and then going and adding the unplug function which replaces the suspend in 3 out of 7 cases. New contributors might get confused about which one to use in the future.
Actually, irq_unplug() should be used in the _unplug() path, as the name implies, I don't think that's confusing :P. My point was more on the fact we probably don't need the dev_enter/exit() sections in the first place, so why introduce a new helper if we can make the _irq_suspend() helper simpler and re-usable for the _unplug() case?
Quoted 3 lines
What we should do is rename suspend to unplug and move the drm_dev_enter/exit() condition at the calling point for the cases where it makes sense.
That'd be even more confusing IMO, why would you call an helper named _unplug() if all you want to do is temporarily suspend the IRQ?
Boris Brezillon
maintainerPATCH v2 3/3 drm/panthor: Actually suspend IRQs in the unplug path
In reply to Boris Brezillonpanthor_xxx_irq_suspend() doesn't mask the interrupts if drm_dev_unplug() has been called, which is always the case when our panthor_xxx_unplug() helpers are called. Fix that by introducing a panthor_xxx_unplug() helper that does what panthor_xxx_irq_suspend() except it does it unconditionally.
v2:
- Add Steve's R-b
---
Found inadvertently while debugging another issue. I guess I managed to call rmmod during a PING and that led to the FW interrupt handler being executed after the device suspend happened.
--- drivers/gpu/drm/panthor/panthor_device.h | 8 ++++++++ drivers/gpu/drm/panthor/panthor_fw.c | 2 +- drivers/gpu/drm/panthor/panthor_gpu.c | 2 +- drivers/gpu/drm/panthor/panthor_mmu.c | 2 +- 4 files changed, 11 insertions(+), 3 deletions(-)
drivers/gpu/drm/panthor/panthor_device.h +8 -0
@@ -321,6 +321,14 @@ static irqreturn_t panthor_ ## __name ## _irq_threaded_handler(int irq, void *dareturn ret; \ } \ \ +static inline void panthor_ ## __name ## _irq_unplug(struct panthor_irq *pirq) \ +{ \ + pirq->mask =0 ; \ + gpu_write(pirq->ptdev, __reg_prefix ## _INT_MASK, 0); \ +synchronize_irq (pirq->irq); \ +atomic_set (&pirq->suspended, true); \ +} \ + \ static inline void panthor_ ## __name ## _irq_suspend(struct panthor_irq *pirq) \ { \int cookie; \
drivers/gpu/drm/panthor/panthor_fw.c +1 -1
@@ -1128,7 +1128,7 @@ void panthor_fw_unplug(struct panthor_device *ptdev)/* Make sure the IRQ handler can be called after that point. */ if (ptdev->fw->irq.irq) -panthor_job_irq_suspend (&ptdev->fw->irq); +panthor_job_irq_unplug (&ptdev->fw->irq);panthor_fw_stop (ptdev);
drivers/gpu/drm/panthor/panthor_gpu.c +1 -1
@@ -174,7 +174,7 @@ void panthor_gpu_unplug(struct panthor_device *ptdev)unsigned long flags;/* Make sure the IRQ handler is not running after that point. */ -panthor_gpu_irq_suspend (&ptdev->gpu->irq); +panthor_gpu_irq_unplug (&ptdev->gpu->irq);/* Wake-up all waiters. */ spin_lock_irqsave (&ptdev->gpu->reqs_lock, flags);
drivers/gpu/drm/panthor/panthor_mmu.c +1 -1
@@ -2622,7 +2622,7 @@ int panthor_vm_prepare_mapped_bos_resvs(struct drm_exec *exec, struct panthor_vm*/ void panthor_mmu_unplug (struct panthor_device *ptdev) { -panthor_mmu_irq_suspend (&ptdev->mmu->irq); +panthor_mmu_irq_unplug (&ptdev->mmu->irq);mutex_lock (&ptdev->mmu->as.slots_lock);for (u32 i =0 ; i <ARRAY_SIZE (ptdev->mmu->as.slots); i++) {
Signature · 1 line
2.44.0
Liviu Dudau
maintainerRe: [PATCH v2 3/3] drm/panthor: Actually suspend IRQs in the unplug path
Quoted 5 lines · Boris Brezillon
panthor_xxx_irq_suspend()doesn't mask the interrupts ifdrm_dev_unplug()has been called, which is always the case when ourpanthor_xxx_unplug()helpers are called. Fix that by introducing apanthor_xxx_unplug()helper that does whatpanthor_xxx_irq_suspend()except it does it unconditionally.
I understand that drm_dev_unplug() messes up with the cleanup, but I'm a bit reluctant to see a function that completely ignores if the device has been unplugged or not. Like mentioned on the review of 2/3, can we move the masking of the interrupts outside the critical section and not add drm_dev_unplug() ?
Quoted 42 lines
v2:
- Add Steve's R-bFixes 5fe909cae118 ("drm/panthor: Add the device logical block")Signed-off-by Boris Brezillon <[email protected]>Reviewed-by Steven Price <[email protected]>---
Found inadvertently while debugging another issue. I guess I managed to call rmmod during a PING and that led to the FW interrupt handler being executed after the device suspend happened.--- drivers/gpu/drm/panthor/panthor_device.h | 8 ++++++++ drivers/gpu/drm/panthor/panthor_fw.c | 2 +- drivers/gpu/drm/panthor/panthor_gpu.c | 2 +- drivers/gpu/drm/panthor/panthor_mmu.c | 2 +- 4 files changed, 11 insertions(+), 3 deletions(-)drivers/gpu/drm/panthor/panthor_device.h +8
-0@@ -321,6 +321,14 @@ static irqreturn_t panthor_ ## __name ## _irq_threaded_handler(int irq, void *dareturn ret; \ } \ \ +static inline void panthor_ ## __name ## _irq_unplug(struct panthor_irq *pirq) \ +{ \ + pirq->mask =0 ; \ + gpu_write(pirq->ptdev, __reg_prefix ## _INT_MASK, 0); \ +synchronize_irq (pirq->irq); \ +atomic_set (&pirq->suspended, true); \ +} \ + \ static inline void panthor_ ## __name ## _irq_suspend(struct panthor_irq *pirq) \ { \int cookie; \drivers/gpu/drm/panthor/panthor_fw.c +0
-0
drivers/gpu/drm/panthor/panthor_fw.c void panthor_fw_unplug(struct panthor_device *ptdev) · line 1129
Quoted 2 lines
drivers/gpu/drm/panthor/panthor_fw.c +0
-0@@ -1128,7 +1128,7 @@ void panthor_fw_unplug(struct panthor_device *ptdev)/* Make sure the IRQ handler can be called after that point. */
While reviewing this I've spotted that the comment needs updating: "... handler *can't* be called ..."
Best regards,
Liviu
Quoted 35 lines
drivers/gpu/drm/panthor/panthor_fw.c +1
-1if (ptdev->fw->irq.irq) -panthor_job_irq_suspend (&ptdev->fw->irq); +panthor_job_irq_unplug (&ptdev->fw->irq);panthor_fw_stop (ptdev);drivers/gpu/drm/panthor/panthor_gpu.c +1
-1@@ -174,7 +174,7 @@ void panthor_gpu_unplug(struct panthor_device *ptdev)unsigned long flags;/* Make sure the IRQ handler is not running after that point. */ -panthor_gpu_irq_suspend (&ptdev->gpu->irq); +panthor_gpu_irq_unplug (&ptdev->gpu->irq);/* Wake-up all waiters. */ spin_lock_irqsave (&ptdev->gpu->reqs_lock, flags);drivers/gpu/drm/panthor/panthor_mmu.c +1
-1@@ -2622,7 +2622,7 @@ int panthor_vm_prepare_mapped_bos_resvs(struct drm_exec *exec, struct panthor_vm*/ void panthor_mmu_unplug (struct panthor_device *ptdev) { -panthor_mmu_irq_suspend (&ptdev->mmu->irq); +panthor_mmu_irq_unplug (&ptdev->mmu->irq);mutex_lock (&ptdev->mmu->as.slots_lock);for (u32 i =0 ; i <ARRAY_SIZE (ptdev->mmu->as.slots); i++) {Signature · 1 line
2.44.0
Signature · 8 lines
====================
| I would like to |
| fix the world, |
| but they're not |
| giving me the |
\ source code! /
---------------
¯\_(ツ)_/¯Boris Brezillon
maintainerRe: [PATCH v2 3/3] drm/panthor: Actually suspend IRQs in the unplug path
Quoted 11 lines · On Mon, 25 Mar 2024 17:24:17 +0000 Liviu Dudau <[email protected]> wrote:
Quoted 5 lines · Boris Brezillon
panthor_xxx_irq_suspend()doesn't mask the interrupts ifdrm_dev_unplug()has been called, which is always the case when ourpanthor_xxx_unplug()helpers are called. Fix that by introducing apanthor_xxx_unplug()helper that does whatpanthor_xxx_irq_suspend()except it does it unconditionally.I understand that
drm_dev_unplug()messes up with the cleanup, but I'm a bit reluctant to see a function that completely ignores if the device has been unplugged or not. Like mentioned on the review of 2/3, can we move the masking of the interrupts outside the critical section and not adddrm_dev_unplug()?
Nope, because the whole point of this drm_dev_enter/exit() section was to prevent accesses to registers when the associated iomem range has been returned to the system after the device has been removed. If you move this gpu_write() outside of the drm_dev_enter/exit() you're better off dropping this check entirely...