[PATCH v2] xen/arm: Do not route NS phys timer IRQ to Xen

Michal Orzel posted 1 patch 1 year, 6 months ago
Patches applied successfully (tree, apply log)
git fetch https://gitlab.com/xen-project/patchew/xen tags/patchew/20221028124937.27677-1-michal.orzel@amd.com
Test gitlab-ci passed
xen/arch/arm/include/asm/perfc_defn.h |  1 -
xen/arch/arm/time.c                   | 34 +++++++++------------------
2 files changed, 11 insertions(+), 24 deletions(-)
[PATCH v2] xen/arm: Do not route NS phys timer IRQ to Xen
Posted by Michal Orzel 1 year, 6 months ago
At the moment, we route NS phys timer IRQ to Xen even though it does not
make use of this timer. Xen uses hypervisor timer for itself and the
physical timer is fully emulated, hence there is nothing that can trigger
such IRQ. This means that requesting/releasing IRQ ends up as a deadcode
as it has no impact on the functional behavior, whereas the code within
a handler ends up being unreachable. This is a left over from the early
days when the CNTHP IRQ was buggy on the HW model used for testing and we
had to use the CNTP instead.

Remove the calls to {request/release}_irq for this timer as well as the
code within the handler. Since timer_interrupt handler is now only used
by the CNTHP, refactor it as follows:
 - rename it to htimer_interrupt to reflect its purpose,
 - remove the IRQ affiliation test,
 - invert the condition to avoid indented code and use unlikely,
 - improve readability by adding new lines \btw code and comments.

Keep the calls to zero the CNTP_CTL_EL0 register for sanity and also
remove the corresponding perf counter definition.

Signed-off-by: Michal Orzel <michal.orzel@amd.com>
---
Changes in v2:
 - take the opportunity to rename the handler, modify the condition to
   avoid the indented code and improve readability.

Based on the outcome of the following discussion:
https://lore.kernel.org/xen-devel/d55938a3-aaca-1d01-b34f-858dbca9830b@amd.com/
---
 xen/arch/arm/include/asm/perfc_defn.h |  1 -
 xen/arch/arm/time.c                   | 34 +++++++++------------------
 2 files changed, 11 insertions(+), 24 deletions(-)

diff --git a/xen/arch/arm/include/asm/perfc_defn.h b/xen/arch/arm/include/asm/perfc_defn.h
index 31f071222b24..3ab0391175d7 100644
--- a/xen/arch/arm/include/asm/perfc_defn.h
+++ b/xen/arch/arm/include/asm/perfc_defn.h
@@ -70,7 +70,6 @@ PERFCOUNTER(spis,                 "#SPIs")
 PERFCOUNTER(guest_irqs,           "#GUEST-IRQS")
 
 PERFCOUNTER(hyp_timer_irqs,   "Hypervisor timer interrupts")
-PERFCOUNTER(phys_timer_irqs,  "Physical timer interrupts")
 PERFCOUNTER(virt_timer_irqs,  "Virtual timer interrupts")
 PERFCOUNTER(maintenance_irqs, "Maintenance interrupts")
 
diff --git a/xen/arch/arm/time.c b/xen/arch/arm/time.c
index dec53b5f7d53..0054cf2b7b78 100644
--- a/xen/arch/arm/time.c
+++ b/xen/arch/arm/time.c
@@ -220,27 +220,18 @@ int reprogram_timer(s_time_t timeout)
 }
 
 /* Handle the firing timer */
-static void timer_interrupt(int irq, void *dev_id, struct cpu_user_regs *regs)
+static void htimer_interrupt(int irq, void *dev_id, struct cpu_user_regs *regs)
 {
-    if ( irq == (timer_irq[TIMER_HYP_PPI]) &&
-         READ_SYSREG(CNTHP_CTL_EL2) & CNTx_CTL_PENDING )
-    {
-        perfc_incr(hyp_timer_irqs);
-        /* Signal the generic timer code to do its work */
-        raise_softirq(TIMER_SOFTIRQ);
-        /* Disable the timer to avoid more interrupts */
-        WRITE_SYSREG(0, CNTHP_CTL_EL2);
-    }
+    if ( unlikely(!(READ_SYSREG(CNTHP_CTL_EL2) & CNTx_CTL_PENDING)) )
+        return;
 
-    if ( irq == (timer_irq[TIMER_PHYS_NONSECURE_PPI]) &&
-         READ_SYSREG(CNTP_CTL_EL0) & CNTx_CTL_PENDING )
-    {
-        perfc_incr(phys_timer_irqs);
-        /* Signal the generic timer code to do its work */
-        raise_softirq(TIMER_SOFTIRQ);
-        /* Disable the timer to avoid more interrupts */
-        WRITE_SYSREG(0, CNTP_CTL_EL0);
-    }
+    perfc_incr(hyp_timer_irqs);
+
+    /* Signal the generic timer code to do its work */
+    raise_softirq(TIMER_SOFTIRQ);
+
+    /* Disable the timer to avoid more interrupts */
+    WRITE_SYSREG(0, CNTHP_CTL_EL2);
 }
 
 static void vtimer_interrupt(int irq, void *dev_id, struct cpu_user_regs *regs)
@@ -302,12 +293,10 @@ void init_timer_interrupt(void)
     WRITE_SYSREG(0, CNTHP_CTL_EL2);   /* Hypervisor's timer disabled */
     isb();
 
-    request_irq(timer_irq[TIMER_HYP_PPI], 0, timer_interrupt,
+    request_irq(timer_irq[TIMER_HYP_PPI], 0, htimer_interrupt,
                 "hyptimer", NULL);
     request_irq(timer_irq[TIMER_VIRT_PPI], 0, vtimer_interrupt,
                    "virtimer", NULL);
-    request_irq(timer_irq[TIMER_PHYS_NONSECURE_PPI], 0, timer_interrupt,
-                "phytimer", NULL);
 
     check_timer_irq_cfg(timer_irq[TIMER_HYP_PPI], "hypervisor");
     check_timer_irq_cfg(timer_irq[TIMER_VIRT_PPI], "virtual");
@@ -326,7 +315,6 @@ static void deinit_timer_interrupt(void)
 
     release_irq(timer_irq[TIMER_HYP_PPI], NULL);
     release_irq(timer_irq[TIMER_VIRT_PPI], NULL);
-    release_irq(timer_irq[TIMER_PHYS_NONSECURE_PPI], NULL);
 }
 
 /* Wait a set number of microseconds */
-- 
2.25.1
Re: [PATCH v2] xen/arm: Do not route NS phys timer IRQ to Xen
Posted by Julien Grall 1 year, 5 months ago
Hi Michal,

On 28/10/2022 14:49, Michal Orzel wrote:
> At the moment, we route NS phys timer IRQ to Xen even though it does not
> make use of this timer. Xen uses hypervisor timer for itself and the
> physical timer is fully emulated, hence there is nothing that can trigger
> such IRQ. This means that requesting/releasing IRQ ends up as a deadcode
> as it has no impact on the functional behavior, whereas the code within
> a handler ends up being unreachable. This is a left over from the early
> days when the CNTHP IRQ was buggy on the HW model used for testing and we
> had to use the CNTP instead.
> 
> Remove the calls to {request/release}_irq for this timer as well as the
> code within the handler. Since timer_interrupt handler is now only used
> by the CNTHP, refactor it as follows:
>   - rename it to htimer_interrupt to reflect its purpose,
>   - remove the IRQ affiliation test,
>   - invert the condition to avoid indented code and use unlikely,
>   - improve readability by adding new lines \btw code and comments.
> 
> Keep the calls to zero the CNTP_CTL_EL0 register for sanity and also
> remove the corresponding perf counter definition.
> 
> Signed-off-by: Michal Orzel <michal.orzel@amd.com>

Reviewed-by: Julien Grall <jgrall@amazon.com>

Cheers,

-- 
Julien Grall
Re: [PATCH v2] xen/arm: Do not route NS phys timer IRQ to Xen
Posted by Julien Grall 1 year, 4 months ago
Hi Michal,

On 24/11/2022 18:57, Julien Grall wrote:
> On 28/10/2022 14:49, Michal Orzel wrote:
>> At the moment, we route NS phys timer IRQ to Xen even though it does not
>> make use of this timer. Xen uses hypervisor timer for itself and the
>> physical timer is fully emulated, hence there is nothing that can trigger
>> such IRQ. This means that requesting/releasing IRQ ends up as a deadcode
>> as it has no impact on the functional behavior, whereas the code within
>> a handler ends up being unreachable. This is a left over from the early
>> days when the CNTHP IRQ was buggy on the HW model used for testing and we
>> had to use the CNTP instead.
>>
>> Remove the calls to {request/release}_irq for this timer as well as the
>> code within the handler. Since timer_interrupt handler is now only used
>> by the CNTHP, refactor it as follows:
>>   - rename it to htimer_interrupt to reflect its purpose,
>>   - remove the IRQ affiliation test,
>>   - invert the condition to avoid indented code and use unlikely,
>>   - improve readability by adding new lines \btw code and comments.
>>
>> Keep the calls to zero the CNTP_CTL_EL0 register for sanity and also
>> remove the corresponding perf counter definition.
>>
>> Signed-off-by: Michal Orzel <michal.orzel@amd.com>
> 
> Reviewed-by: Julien Grall <jgrall@amazon.com>

Committed.

Cheers,

-- 
Julien Grall