From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-6.8 required=3.0 tests=DKIMWL_WL_HIGH,DKIM_SIGNED, DKIM_VALID,HEADER_FROM_DIFFERENT_DOMAINS,MAILING_LIST_MULTI,SIGNED_OFF_BY, SPF_HELO_NONE,SPF_PASS,URIBL_BLOCKED,USER_AGENT_GIT autolearn=unavailable autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 56824C3A5A8 for ; Wed, 4 Sep 2019 18:17:24 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id 260CE206B8 for ; Wed, 4 Sep 2019 18:17:24 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1567621044; bh=YSK6LrnGrgX8dgr3dQc5JYWpcMtEsuYrTfbN4w1K9BE=; h=From:To:Cc:Subject:Date:In-Reply-To:References:List-ID:From; b=vCk/ZO8nsyoW9x8IofzHwI2wwj2h5Z9Cfpj7L06rrWwRIjyJ4ax23+c9LNA+kzw26 SKV8VCcBstgL2PevrlGvf4CBrDifRNTOynUDWdd8dURwRzqcZXeqZHCjz/AopD669T +CCHK+/HE2oNTsvkPvj8N9xiC9dHvLaMtQXvM1ik= Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S2389466AbfIDSM6 (ORCPT ); Wed, 4 Sep 2019 14:12:58 -0400 Received: from mail.kernel.org ([198.145.29.99]:57470 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S2389947AbfIDSMz (ORCPT ); Wed, 4 Sep 2019 14:12:55 -0400 Received: from localhost (83-86-89-107.cable.dynamic.v4.ziggo.nl [83.86.89.107]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPSA id 9FB2F22CEA; Wed, 4 Sep 2019 18:12:53 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1567620774; bh=YSK6LrnGrgX8dgr3dQc5JYWpcMtEsuYrTfbN4w1K9BE=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=d3bETdp5YSCd1Iq+hWsbcrVBWiwouF5vnrsEUd2N92y1ivpoPQKDGTwO9xVZddpp1 K1wXj61JAq4e7PXdNWpqz1A7Ua7nv1LuaX8zzeIpb6M552oMx+0vitpvsibFSP04vi fAHNGfR7Ghfq8GPlw+dqKH5FDGWjlFJUBe2goULg= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Zenghui Yu , Heyi Guo , Marc Zyngier , Will Deacon Subject: [PATCH 5.2 089/143] KVM: arm/arm64: vgic: Fix potential deadlock when ap_list is long Date: Wed, 4 Sep 2019 19:53:52 +0200 Message-Id: <20190904175317.574570584@linuxfoundation.org> X-Mailer: git-send-email 2.23.0 In-Reply-To: <20190904175314.206239922@linuxfoundation.org> References: <20190904175314.206239922@linuxfoundation.org> User-Agent: quilt/0.66 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Sender: stable-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: stable@vger.kernel.org From: Heyi Guo commit d4a8061a7c5f7c27a2dc002ee4cb89b3e6637e44 upstream. If the ap_list is longer than 256 entries, merge_final() in list_sort() will call the comparison callback with the same element twice, causing a deadlock in vgic_irq_cmp(). Fix it by returning early when irqa == irqb. Cc: stable@vger.kernel.org # 4.7+ Fixes: 8e4447457965 ("KVM: arm/arm64: vgic-new: Add IRQ sorting") Signed-off-by: Zenghui Yu Signed-off-by: Heyi Guo [maz: massaged commit log and patch, added Fixes and Cc-stable] Signed-off-by: Marc Zyngier Signed-off-by: Will Deacon Signed-off-by: Greg Kroah-Hartman --- virt/kvm/arm/vgic/vgic.c | 7 +++++++ 1 file changed, 7 insertions(+) --- a/virt/kvm/arm/vgic/vgic.c +++ b/virt/kvm/arm/vgic/vgic.c @@ -254,6 +254,13 @@ static int vgic_irq_cmp(void *priv, stru bool penda, pendb; int ret; + /* + * list_sort may call this function with the same element when + * the list is fairly long. + */ + if (unlikely(irqa == irqb)) + return 0; + raw_spin_lock(&irqa->irq_lock); raw_spin_lock_nested(&irqb->irq_lock, SINGLE_DEPTH_NESTING);