]> git.ipfire.org Git - thirdparty/kernel/stable-queue.git/commitdiff
5.10-stable patches
authorGreg Kroah-Hartman <gregkh@linuxfoundation.org>
Mon, 21 Oct 2024 08:24:18 +0000 (10:24 +0200)
committerGreg Kroah-Hartman <gregkh@linuxfoundation.org>
Mon, 21 Oct 2024 08:24:18 +0000 (10:24 +0200)
added patches:
irqchip-gic-v4-don-t-allow-a-vmovp-on-a-dying-vpe.patch

queue-5.10/irqchip-gic-v4-don-t-allow-a-vmovp-on-a-dying-vpe.patch [new file with mode: 0644]
queue-5.10/series

diff --git a/queue-5.10/irqchip-gic-v4-don-t-allow-a-vmovp-on-a-dying-vpe.patch b/queue-5.10/irqchip-gic-v4-don-t-allow-a-vmovp-on-a-dying-vpe.patch
new file mode 100644 (file)
index 0000000..5b9a728
--- /dev/null
@@ -0,0 +1,103 @@
+From 1442ee0011983f0c5c4b92380e6853afb513841a Mon Sep 17 00:00:00 2001
+From: Marc Zyngier <maz@kernel.org>
+Date: Wed, 2 Oct 2024 21:49:59 +0100
+Subject: irqchip/gic-v4: Don't allow a VMOVP on a dying VPE
+
+From: Marc Zyngier <maz@kernel.org>
+
+commit 1442ee0011983f0c5c4b92380e6853afb513841a upstream.
+
+Kunkun Jiang reported that there is a small window of opportunity for
+userspace to force a change of affinity for a VPE while the VPE has already
+been unmapped, but the corresponding doorbell interrupt still visible in
+/proc/irq/.
+
+Plug the race by checking the value of vmapp_count, which tracks whether
+the VPE is mapped ot not, and returning an error in this case.
+
+This involves making vmapp_count common to both GICv4.1 and its v4.0
+ancestor.
+
+Fixes: 64edfaa9a234 ("irqchip/gic-v4.1: Implement the v4.1 flavour of VMAPP")
+Reported-by: Kunkun Jiang <jiangkunkun@huawei.com>
+Signed-off-by: Marc Zyngier <maz@kernel.org>
+Signed-off-by: Thomas Gleixner <tglx@linutronix.de>
+Cc: stable@vger.kernel.org
+Link: https://lore.kernel.org/r/c182ece6-2ba0-ce4f-3404-dba7a3ab6c52@huawei.com
+Link: https://lore.kernel.org/all/20241002204959.2051709-1-maz@kernel.org
+Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
+---
+ drivers/irqchip/irq-gic-v3-its.c   |   18 ++++++++++++------
+ include/linux/irqchip/arm-gic-v4.h |    4 +++-
+ 2 files changed, 15 insertions(+), 7 deletions(-)
+
+--- a/drivers/irqchip/irq-gic-v3-its.c
++++ b/drivers/irqchip/irq-gic-v3-its.c
+@@ -789,8 +789,8 @@ static struct its_vpe *its_build_vmapp_c
+       its_encode_valid(cmd, desc->its_vmapp_cmd.valid);
+       if (!desc->its_vmapp_cmd.valid) {
++              alloc = !atomic_dec_return(&desc->its_vmapp_cmd.vpe->vmapp_count);
+               if (is_v4_1(its)) {
+-                      alloc = !atomic_dec_return(&desc->its_vmapp_cmd.vpe->vmapp_count);
+                       its_encode_alloc(cmd, alloc);
+                       /*
+                        * Unmapping a VPE is self-synchronizing on GICv4.1,
+@@ -809,13 +809,13 @@ static struct its_vpe *its_build_vmapp_c
+       its_encode_vpt_addr(cmd, vpt_addr);
+       its_encode_vpt_size(cmd, LPI_NRBITS - 1);
++      alloc = !atomic_fetch_inc(&desc->its_vmapp_cmd.vpe->vmapp_count);
++
+       if (!is_v4_1(its))
+               goto out;
+       vconf_addr = virt_to_phys(page_address(desc->its_vmapp_cmd.vpe->its_vm->vprop_page));
+-      alloc = !atomic_fetch_inc(&desc->its_vmapp_cmd.vpe->vmapp_count);
+-
+       its_encode_alloc(cmd, alloc);
+       /* We can only signal PTZ when alloc==1. Why do we have two bits? */
+@@ -3793,6 +3793,13 @@ static int its_vpe_set_affinity(struct i
+       int from, cpu;
+       /*
++       * Check if we're racing against a VPE being destroyed, for
++       * which we don't want to allow a VMOVP.
++       */
++      if (!atomic_read(&vpe->vmapp_count))
++              return -EINVAL;
++
++      /*
+        * Changing affinity is mega expensive, so let's be as lazy as
+        * we can and only do it if we really have to. Also, if mapped
+        * into the proxy device, we need to move the doorbell
+@@ -4424,9 +4431,8 @@ static int its_vpe_init(struct its_vpe *
+       raw_spin_lock_init(&vpe->vpe_lock);
+       vpe->vpe_id = vpe_id;
+       vpe->vpt_page = vpt_page;
+-      if (gic_rdists->has_rvpeid)
+-              atomic_set(&vpe->vmapp_count, 0);
+-      else
++      atomic_set(&vpe->vmapp_count, 0);
++      if (!gic_rdists->has_rvpeid)
+               vpe->vpe_proxy_event = -1;
+       return 0;
+--- a/include/linux/irqchip/arm-gic-v4.h
++++ b/include/linux/irqchip/arm-gic-v4.h
+@@ -56,10 +56,12 @@ struct its_vpe {
+                               bool    enabled;
+                               bool    group;
+                       }                       sgi_config[16];
+-                      atomic_t vmapp_count;
+               };
+       };
++      /* Track the VPE being mapped */
++      atomic_t vmapp_count;
++
+       /*
+        * Ensures mutual exclusion between affinity setting of the
+        * vPE and vLPI operations using vpe->col_idx.
index caacf96f121b8ffdd3fba7b95a2646eac6c18872..08f1ff5d880f5f95b5bb0446048d4d28f2aefb89 100644 (file)
@@ -43,3 +43,4 @@ x86-resctrl-annotate-get_mem_config-functions-as-__init.patch
 x86-apic-always-explicitly-disarm-tsc-deadline-timer.patch
 x86-entry_32-do-not-clobber-user-eflags.zf.patch
 x86-entry_32-clear-cpu-buffers-after-register-restore-in-nmi-return.patch
+irqchip-gic-v4-don-t-allow-a-vmovp-on-a-dying-vpe.patch