stable.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH v2 3/3] xen/events: Update virq_to_irq on migration
       [not found] <20250826005517.41547-1-jason.andryuk@amd.com>
@ 2025-08-26  0:55 ` Jason Andryuk
  2025-08-27 15:28   ` Jürgen Groß
  0 siblings, 1 reply; 2+ messages in thread
From: Jason Andryuk @ 2025-08-26  0:55 UTC (permalink / raw)
  To: Juergen Gross, Stefano Stabellini, Oleksandr Tyshchenko,
	Chris Wright, Jeremy Fitzhardinge
  Cc: Jason Andryuk, stable, xen-devel, linux-kernel

VIRQs come in 3 flavors, per-VPU, per-domain, and global, and the VIRQs
are tracked in per-cpu virq_to_irq arrays.

Per-domain and global VIRQs must be bound on CPU 0, and
bind_virq_to_irq() sets the per_cpu virq_to_irq at registration time
Later, the interrupt can migrate, and info->cpu is updated.  When
calling __unbind_from_irq(), the per-cpu virq_to_irq is cleared for a
different cpu.  If bind_virq_to_irq() is called again with CPU 0, the
stale irq is returned.  There won't be any irq_info for the irq, so
things break.

Make xen_rebind_evtchn_to_cpu() update the per_cpu virq_to_irq mappings
to keep them update to date with the current cpu.  This ensures the
correct virq_to_irq is cleared in __unbind_from_irq().

Fixes: e46cdb66c8fc ("xen: event channels")
Cc: stable@vger.kernel.org
Signed-off-by: Jason Andryuk <jason.andryuk@amd.com>
---
V2:
Different approach changing virq_to_irq
---
 drivers/xen/events/events_base.c | 11 +++++++++++
 1 file changed, 11 insertions(+)

diff --git a/drivers/xen/events/events_base.c b/drivers/xen/events/events_base.c
index a85bc43f4344..4e9db7b92dde 100644
--- a/drivers/xen/events/events_base.c
+++ b/drivers/xen/events/events_base.c
@@ -1772,6 +1772,7 @@ static int xen_rebind_evtchn_to_cpu(struct irq_info *info, unsigned int tcpu)
 {
 	struct evtchn_bind_vcpu bind_vcpu;
 	evtchn_port_t evtchn = info ? info->evtchn : 0;
+	int old_cpu = info ? info->cpu : tcpu;
 
 	if (!VALID_EVTCHN(evtchn))
 		return -1;
@@ -1795,8 +1796,18 @@ static int xen_rebind_evtchn_to_cpu(struct irq_info *info, unsigned int tcpu)
 	 * it, but don't do the xenlinux-level rebind in that case.
 	 */
 	if (HYPERVISOR_event_channel_op(EVTCHNOP_bind_vcpu, &bind_vcpu) >= 0)
+	{
 		bind_evtchn_to_cpu(info, tcpu, false);
 
+		if (info->type == IRQT_VIRQ) {
+			int virq = info->u.virq;
+			int irq = per_cpu(virq_to_irq, old_cpu)[virq];
+
+			per_cpu(virq_to_irq, old_cpu)[virq] = -1;
+			per_cpu(virq_to_irq, tcpu)[virq] = irq;
+		}
+	}
+
 	do_unmask(info, EVT_MASK_REASON_TEMPORARY);
 
 	return 0;
-- 
2.50.1


^ permalink raw reply related	[flat|nested] 2+ messages in thread

* Re: [PATCH v2 3/3] xen/events: Update virq_to_irq on migration
  2025-08-26  0:55 ` [PATCH v2 3/3] xen/events: Update virq_to_irq on migration Jason Andryuk
@ 2025-08-27 15:28   ` Jürgen Groß
  0 siblings, 0 replies; 2+ messages in thread
From: Jürgen Groß @ 2025-08-27 15:28 UTC (permalink / raw)
  To: Jason Andryuk, Stefano Stabellini, Oleksandr Tyshchenko,
	Chris Wright, Jeremy Fitzhardinge
  Cc: stable, xen-devel, linux-kernel


[-- Attachment #1.1.1: Type: text/plain, Size: 2470 bytes --]

On 26.08.25 02:55, Jason Andryuk wrote:
> VIRQs come in 3 flavors, per-VPU, per-domain, and global, and the VIRQs
> are tracked in per-cpu virq_to_irq arrays.
> 
> Per-domain and global VIRQs must be bound on CPU 0, and
> bind_virq_to_irq() sets the per_cpu virq_to_irq at registration time
> Later, the interrupt can migrate, and info->cpu is updated.  When
> calling __unbind_from_irq(), the per-cpu virq_to_irq is cleared for a
> different cpu.  If bind_virq_to_irq() is called again with CPU 0, the
> stale irq is returned.  There won't be any irq_info for the irq, so
> things break.
> 
> Make xen_rebind_evtchn_to_cpu() update the per_cpu virq_to_irq mappings
> to keep them update to date with the current cpu.  This ensures the
> correct virq_to_irq is cleared in __unbind_from_irq().
> 
> Fixes: e46cdb66c8fc ("xen: event channels")
> Cc: stable@vger.kernel.org
> Signed-off-by: Jason Andryuk <jason.andryuk@amd.com>
> ---
> V2:
> Different approach changing virq_to_irq
> ---
>   drivers/xen/events/events_base.c | 11 +++++++++++
>   1 file changed, 11 insertions(+)
> 
> diff --git a/drivers/xen/events/events_base.c b/drivers/xen/events/events_base.c
> index a85bc43f4344..4e9db7b92dde 100644
> --- a/drivers/xen/events/events_base.c
> +++ b/drivers/xen/events/events_base.c
> @@ -1772,6 +1772,7 @@ static int xen_rebind_evtchn_to_cpu(struct irq_info *info, unsigned int tcpu)
>   {
>   	struct evtchn_bind_vcpu bind_vcpu;
>   	evtchn_port_t evtchn = info ? info->evtchn : 0;
> +	int old_cpu = info ? info->cpu : tcpu;

I'd prefer not to initialize old_cpu just here ...

>   
>   	if (!VALID_EVTCHN(evtchn))
>   		return -1;

... as here info is always valid, so you can just use "old_cpu = info->cpu;"
(probably just after the hypercall).

> @@ -1795,8 +1796,18 @@ static int xen_rebind_evtchn_to_cpu(struct irq_info *info, unsigned int tcpu)
>   	 * it, but don't do the xenlinux-level rebind in that case.
>   	 */
>   	if (HYPERVISOR_event_channel_op(EVTCHNOP_bind_vcpu, &bind_vcpu) >= 0)
> +	{

Kernel style, please.

>   		bind_evtchn_to_cpu(info, tcpu, false);
>   
> +		if (info->type == IRQT_VIRQ) {
> +			int virq = info->u.virq;
> +			int irq = per_cpu(virq_to_irq, old_cpu)[virq];
> +
> +			per_cpu(virq_to_irq, old_cpu)[virq] = -1;
> +			per_cpu(virq_to_irq, tcpu)[virq] = irq;
> +		}
> +	}
> +
>   	do_unmask(info, EVT_MASK_REASON_TEMPORARY);
>   
>   	return 0;


Juergen

[-- Attachment #1.1.2: OpenPGP public key --]
[-- Type: application/pgp-keys, Size: 3743 bytes --]

[-- Attachment #2: OpenPGP digital signature --]
[-- Type: application/pgp-signature, Size: 495 bytes --]

^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2025-08-27 15:28 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
     [not found] <20250826005517.41547-1-jason.andryuk@amd.com>
2025-08-26  0:55 ` [PATCH v2 3/3] xen/events: Update virq_to_irq on migration Jason Andryuk
2025-08-27 15:28   ` Jürgen Groß

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).