Received: by 2002:a25:c593:0:0:0:0:0 with SMTP id v141csp1021339ybe; Wed, 4 Sep 2019 11:15:46 -0700 (PDT) X-Google-Smtp-Source: APXvYqzSmOe+2vXah0BSLLuLCx2ZxESoaRRFHKp7B1X2Gcaf7wis8eyMf2IxUQzbY+5wcsRkOOmG X-Received: by 2002:a63:e948:: with SMTP id q8mr35147791pgj.93.1567620946686; Wed, 04 Sep 2019 11:15:46 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1567620946; cv=none; d=google.com; s=arc-20160816; b=E4SL++yoaPyVASQuz5zxvNSqziAG6xYKi7/NuNd19g/q+5ajxSd9f0CzJYSb59iuYp it3Jau1aSvwQoVMavi08l5qLFBfRNiuGHWmLrUdnTptqORiNOen1YdghFrd49sv46pfQ gB3T+JNlaS5sxsmyk5tA6w7bXTOLw7E3OH/kDhHyNrso1cROYYNxcHI0FYy9EH1YU9QP gueNpFqPD9SQHDxfS0aSKW69s0wccGKoSuF9OfuJHaxsOPkGYLSgg8B7iYNUiQNDIkd3 TJGEafqWMRDkmns3MmpU+T3pBK9VkKpQP4yXDogoE9UBtQOa3O7iJNSHTWFULvP992kN Z5Iw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:content-transfer-encoding:mime-version :user-agent:references:in-reply-to:message-id:date:subject:cc:to :from:dkim-signature; bh=YEMgsdAnBbvMXVJ57AUSrQ2xx/VWtbK8Y6T+u6Y6lLw=; b=Zrzr9V2X6wPbCWlt9W8vsF9RjfG4KvAHtFaBnMq+Hr6H8d53btW4sR1AFEzJlOnLbj oWvEE20999DbEoTcQuJmduUygz+LuDHWfei8pDL/0+Lh6mPOvzMBlFKDIpYXCTORFsE2 n5KNCr9Pt8z90JUoANZvSUC7X8GuZRHK0cL1puhZmsD+xJyn2DgAi9tB1Vhl0r/TLAf4 i8PaumwdLnFsh322rJjIAHyuDJ25iO5/Bi8PW3pNK6/iu53RCVsLr09zCVMZYA6ThFWk eOs+Yq2mzAUqP2PIbXwIhRIjR3URsqLN+nE/MsUC0Z+/FTpOnqDZZKycF+fvI83YFTWI YVQg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=d3bETdp5; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id b14si17711257pgi.587.2019.09.04.11.15.30; Wed, 04 Sep 2019 11:15:46 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=d3bETdp5; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S2390590AbfIDSM6 (ORCPT + 99 others); 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: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@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);