* Re: [PATCH] MIPS: cevt-r4k: Don't call get_c0_compare_int if timer irq is installed
2024-08-13 9:59 [PATCH] MIPS: cevt-r4k: Don't call get_c0_compare_int if timer irq is installed Jiaxun Yang
@ 2024-08-16 11:40 ` Philippe Mathieu-Daudé
2024-08-19 10:42 ` Serge Semin
2024-08-22 7:58 ` Thomas Bogendoerfer
2 siblings, 0 replies; 4+ messages in thread
From: Philippe Mathieu-Daudé @ 2024-08-16 11:40 UTC (permalink / raw)
To: Jiaxun Yang, Thomas Bogendoerfer
Cc: linux-mips, linux-kernel, Serge Semin, Frederic Weisbecker,
Thomas Gleixner, Ingo Molnar, Daniel Lezcano
Hi Jiaxun,
+Daniel/Thomas for CLOCKEVENTS
On 13/8/24 11:59, Jiaxun Yang wrote:
> This avoids warning:
>
> [ 0.118053] BUG: sleeping function called from invalid context at kernel/locking/mutex.c:283
>
> Caused by get_c0_compare_int on secondary CPU.
>
> We also skipped saving IRQ number to struct clock_event_device *cd as
> it's never used by clockevent core, as per comments it's only meant
> for "non CPU local devices".
>
> Reported-by: Serge Semin <fancer.lancer@gmail.com>
> Closes: https://lore.kernel.org/linux-mips/6szkkqxpsw26zajwysdrwplpjvhl5abpnmxgu2xuj3dkzjnvsf@4daqrz4mf44k/
> Signed-off-by: Jiaxun Yang <jiaxun.yang@flygoat.com>
> ---
> arch/mips/kernel/cevt-r4k.c | 15 +++++++--------
> 1 file changed, 7 insertions(+), 8 deletions(-)
>
> diff --git a/arch/mips/kernel/cevt-r4k.c b/arch/mips/kernel/cevt-r4k.c
> index 368e8475870f..5f6e9e2ebbdb 100644
> --- a/arch/mips/kernel/cevt-r4k.c
> +++ b/arch/mips/kernel/cevt-r4k.c
> @@ -303,13 +303,6 @@ int r4k_clockevent_init(void)
> if (!c0_compare_int_usable())
> return -ENXIO;
>
> - /*
> - * With vectored interrupts things are getting platform specific.
> - * get_c0_compare_int is a hook to allow a platform to return the
> - * interrupt number of its liking.
> - */
> - irq = get_c0_compare_int();
> -
> cd = &per_cpu(mips_clockevent_device, cpu);
>
> cd->name = "MIPS";
> @@ -320,7 +313,6 @@ int r4k_clockevent_init(void)
> min_delta = calculate_min_delta();
>
> cd->rating = 300;
> - cd->irq = irq;
What should be the unset value is not clear, clock_event_device::irq
is an int, described in <linux/clockchips.h> as:
@irq: IRQ number (only for non CPU local devices)
Most arch clocks set irq > 0 or don't set it.
Core code / drivers check for irq != -1, irq != 0 or irq >= 0:
kernel/time/tick-common.c-295- if (newdev->irq >= 0 &&
!irq_can_set_affinity(newdev->irq))
kernel/time/tick-common.c-296- return false;
drivers/clocksource/exynos_mct.c-479- if (evt->irq == -1)
drivers/clocksource/exynos_mct.c-480- return -EIO;
drivers/clocksource/timer-ti-dm-systimer.c-562- if (!dev->irq)
drivers/clocksource/timer-ti-dm-systimer.c-563- return -ENXIO;
Using -1 for unset value seems reasonable, but since most don't set
this default value, I guess that's OK to do the same.
Reviewed-by: Philippe Mathieu-Daudé <philmd@linaro.org>
> cd->cpumask = cpumask_of(cpu);
> cd->set_next_event = mips_next_event;
> cd->event_handler = mips_event_handler;
> @@ -332,6 +324,13 @@ int r4k_clockevent_init(void)
>
> cp0_timer_irq_installed = 1;
>
> + /*
> + * With vectored interrupts things are getting platform specific.
> + * get_c0_compare_int is a hook to allow a platform to return the
> + * interrupt number of its liking.
> + */
> + irq = get_c0_compare_int();
> +
> if (request_irq(irq, c0_compare_interrupt, flags, "timer",
> c0_compare_interrupt))
> pr_err("Failed to request irq %d (timer)\n", irq);
>
> ---
> base-commit: 9e6869691724b12e1f43655eeedc35fade38120c
> change-id: 20240812-get_c0_compare_int-66935853a308
>
> Best regards,
^ permalink raw reply [flat|nested] 4+ messages in thread* Re: [PATCH] MIPS: cevt-r4k: Don't call get_c0_compare_int if timer irq is installed
2024-08-13 9:59 [PATCH] MIPS: cevt-r4k: Don't call get_c0_compare_int if timer irq is installed Jiaxun Yang
2024-08-16 11:40 ` Philippe Mathieu-Daudé
@ 2024-08-19 10:42 ` Serge Semin
2024-08-22 7:58 ` Thomas Bogendoerfer
2 siblings, 0 replies; 4+ messages in thread
From: Serge Semin @ 2024-08-19 10:42 UTC (permalink / raw)
To: Jiaxun Yang; +Cc: Thomas Bogendoerfer, linux-mips, linux-kernel
Hi Jiaxun
On Tue, Aug 13, 2024 at 10:59:08AM +0100, Jiaxun Yang wrote:
> This avoids warning:
>
> [ 0.118053] BUG: sleeping function called from invalid context at kernel/locking/mutex.c:283
>
> Caused by get_c0_compare_int on secondary CPU.
>
> We also skipped saving IRQ number to struct clock_event_device *cd as
> it's never used by clockevent core, as per comments it's only meant
> for "non CPU local devices".
>
> Reported-by: Serge Semin <fancer.lancer@gmail.com>
> Closes: https://lore.kernel.org/linux-mips/6szkkqxpsw26zajwysdrwplpjvhl5abpnmxgu2xuj3dkzjnvsf@4daqrz4mf44k/
> Signed-off-by: Jiaxun Yang <jiaxun.yang@flygoat.com>
The solution works well for me. Thanks!
Reviewed-by: Serge Semin <fancer.lancer@gmail.com>
Tested-by: Serge Semin <fancer.lancer@gmail.com>
-Serge(y)
> ---
> arch/mips/kernel/cevt-r4k.c | 15 +++++++--------
> 1 file changed, 7 insertions(+), 8 deletions(-)
>
> diff --git a/arch/mips/kernel/cevt-r4k.c b/arch/mips/kernel/cevt-r4k.c
> index 368e8475870f..5f6e9e2ebbdb 100644
> --- a/arch/mips/kernel/cevt-r4k.c
> +++ b/arch/mips/kernel/cevt-r4k.c
> @@ -303,13 +303,6 @@ int r4k_clockevent_init(void)
> if (!c0_compare_int_usable())
> return -ENXIO;
>
> - /*
> - * With vectored interrupts things are getting platform specific.
> - * get_c0_compare_int is a hook to allow a platform to return the
> - * interrupt number of its liking.
> - */
> - irq = get_c0_compare_int();
> -
> cd = &per_cpu(mips_clockevent_device, cpu);
>
> cd->name = "MIPS";
> @@ -320,7 +313,6 @@ int r4k_clockevent_init(void)
> min_delta = calculate_min_delta();
>
> cd->rating = 300;
> - cd->irq = irq;
> cd->cpumask = cpumask_of(cpu);
> cd->set_next_event = mips_next_event;
> cd->event_handler = mips_event_handler;
> @@ -332,6 +324,13 @@ int r4k_clockevent_init(void)
>
> cp0_timer_irq_installed = 1;
>
> + /*
> + * With vectored interrupts things are getting platform specific.
> + * get_c0_compare_int is a hook to allow a platform to return the
> + * interrupt number of its liking.
> + */
> + irq = get_c0_compare_int();
> +
> if (request_irq(irq, c0_compare_interrupt, flags, "timer",
> c0_compare_interrupt))
> pr_err("Failed to request irq %d (timer)\n", irq);
>
> ---
> base-commit: 9e6869691724b12e1f43655eeedc35fade38120c
> change-id: 20240812-get_c0_compare_int-66935853a308
>
> Best regards,
> --
> Jiaxun Yang <jiaxun.yang@flygoat.com>
>
^ permalink raw reply [flat|nested] 4+ messages in thread* Re: [PATCH] MIPS: cevt-r4k: Don't call get_c0_compare_int if timer irq is installed
2024-08-13 9:59 [PATCH] MIPS: cevt-r4k: Don't call get_c0_compare_int if timer irq is installed Jiaxun Yang
2024-08-16 11:40 ` Philippe Mathieu-Daudé
2024-08-19 10:42 ` Serge Semin
@ 2024-08-22 7:58 ` Thomas Bogendoerfer
2 siblings, 0 replies; 4+ messages in thread
From: Thomas Bogendoerfer @ 2024-08-22 7:58 UTC (permalink / raw)
To: Jiaxun Yang; +Cc: linux-mips, linux-kernel, Serge Semin
On Tue, Aug 13, 2024 at 10:59:08AM +0100, Jiaxun Yang wrote:
> This avoids warning:
>
> [ 0.118053] BUG: sleeping function called from invalid context at kernel/locking/mutex.c:283
>
> Caused by get_c0_compare_int on secondary CPU.
>
> We also skipped saving IRQ number to struct clock_event_device *cd as
> it's never used by clockevent core, as per comments it's only meant
> for "non CPU local devices".
>
> Reported-by: Serge Semin <fancer.lancer@gmail.com>
> Closes: https://lore.kernel.org/linux-mips/6szkkqxpsw26zajwysdrwplpjvhl5abpnmxgu2xuj3dkzjnvsf@4daqrz4mf44k/
> Signed-off-by: Jiaxun Yang <jiaxun.yang@flygoat.com>
> ---
> arch/mips/kernel/cevt-r4k.c | 15 +++++++--------
> 1 file changed, 7 insertions(+), 8 deletions(-)
applied to mips-fixes.
Thomas.
--
Crap can work. Given enough thrust pigs will fly, but it's not necessarily a
good idea. [ RFC1925, 2.3 ]
^ permalink raw reply [flat|nested] 4+ messages in thread