Commit c2131e42 authored by Marc Zyngier's avatar Marc Zyngier Committed by zhangyuyang
Browse files

irqchip/gic-v4: Fix ordering between vmapp and vpe locks

mainline inclusion
from mainline-v6.11-rc7
commit f97fd458763a4801d04dbb4a79d9ca6282d293ec
category: other
bugzilla: https://gitee.com/openeuler/kernel/issues/IAVK49

Reference: https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git/commit/?id=f97fd458763a4801d04dbb4a79d9ca6282d293ec



-----------------------------------------------------------------

The recently established lock ordering mandates that the per-VM
vmapp_lock is acquired before taking the per-VPE lock.

As it turns out, its_vpe_set_affinity() takes the VPE lock, and
then calls into its_send_vmovp(), which itself takes the vmapp
lock. Obviously, this is a lock order violation.

As its_send_vmovp() is only called from its_vpe_set_affinity(),
hoist the vmapp locking from the former into the latter, restoring
the expected order.

Fixes: f0eb154c39471 ("irqchip/gic-v4: Substitute vmovp_lock for a per-VM lock")
Reported-by: default avatarZhou Wang <wangzhou1@hisilicon.com>
Signed-off-by: default avatarMarc Zyngier <maz@kernel.org>
Signed-off-by: default avatarThomas Gleixner <tglx@linutronix.de>
Link: https://lore.kernel.org/all/20240818171625.3030584-1-maz@kernel.org


Signed-off-by: default avatarcaijian <caijian11@h-partners.com>
parent f7186cb9
Loading
Loading
Loading
Loading
+10 −6
Original line number Diff line number Diff line
@@ -1656,12 +1656,6 @@ static void its_send_vmovp(struct its_vpe *vpe)
		return;
	}

	/*
	 * Protect against concurrent updates of the mapping state on
	 * individual VMs.
	 */
	guard(raw_spinlock_irqsave)(&vpe->its_vm->vmapp_lock);

	/*
	 * Yet another marvel of the architecture. If using the
	 * its_list "feature", we need to make sure that all ITSs
@@ -4269,7 +4263,14 @@ static int its_vpe_set_affinity(struct irq_data *d,
	 * protect us, and that we must ensure nobody samples vpe->col_idx
	 * during the update, hence the lock below which must also be
	 * taken on any vLPI handling path that evaluates vpe->col_idx.
	 *
	 * Finally, we must protect ourselves against concurrent updates of
	 * the mapping state on this VM should the ITS list be in use (see
	 * the shortcut in its_send_vmovp() otherewise).
	 */
	if (its_list_map)
		raw_spin_lock(&vpe->its_vm->vmapp_lock);

	from = vpe_to_cpuid_lock(vpe, &flags);
	table_mask = gic_data_rdist_cpu(from)->vpe_table_mask;

@@ -4294,6 +4295,9 @@ static int its_vpe_set_affinity(struct irq_data *d,
	irq_data_update_effective_affinity(d, cpumask_of(cpu));
	vpe_to_cpuid_unlock(vpe, flags);

	if (its_list_map)
		raw_spin_unlock(&vpe->its_vm->vmapp_lock);

	return IRQ_SET_MASK_OK_DONE;
}