Received: by 2002:a25:c593:0:0:0:0:0 with SMTP id v141csp1012897ybe; Wed, 4 Sep 2019 11:08:16 -0700 (PDT) X-Google-Smtp-Source: APXvYqxSrtbqlbV1GCxTLzSgd3Lw53ENwjTHVSCF4RaALJsKtExON8wYVAYDHXv3UBV7RBwZBse0 X-Received: by 2002:a63:ec13:: with SMTP id j19mr35683737pgh.369.1567620496714; Wed, 04 Sep 2019 11:08:16 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1567620496; cv=none; d=google.com; s=arc-20160816; b=l4lcLrBBAT11DJbzTbTGhyou/CSLR3jpfAvO7v6qwqwwjnxQdnYNVynVRU7UJb1nTt 7UDx8mlBOyj7zsL1coxOcKTh+8SywvOHeHOsUdz+LcxeEkchbDGpHmGAXu7Sy0RiWTpX SrdMT9P61wwoxuaaJCgAHusYr9sYz6LrGD4AIhlaHx1fuMUQPuFYak993aw58k8MzAte 9kHaJjnUPsnI9+0iTDzIsZBvzgRR9Tp9dhmSoLdEF6b2Ee+hkUhgHYyJUvGLcEnctr5w hqttNFOduGYniKRqfrRw5FlYDCZqvvNGjT6fUULNaMbtri+/DkDSxPE3ZlF6r3ED20HZ Pm+A== 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=QcMCcH67ofqmufQPQLp0csQ274T7fFo/Fqok8pa9lN4=; b=ApNApZiHt5398Dt3ikQN10Esb9bMIVXBbg1HEt5Rl522Uc3TUIS1vWPGO5oEHRhIQn YBSkOj7E/GtB0tKwg8Kx/7zmyid7FvAVT7+ll0QiOxAHrTgb7pwBwHnp2G9FOY2rHJS1 eylc8mG7yZQdXoAKtCGO0evkKpBZsJrHDCC7JItvITixEhoK8fgTRif2yLyAayRhamdk RsYN/qB2aJl7zbA/wo/i3HfLkA0lCEgvOM8QixLvYI0uvDWfXg7BGJmA1CBNssuTSydc GxIoQBSDikcorNSAHu7bjMfhmqQUujDu2bKiaF8NocuAItyQ2sM9fIBNdonCxUwORCRF BfRA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b="o/TREYCp"; 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 z22si17073287pgv.551.2019.09.04.11.07.59; Wed, 04 Sep 2019 11:08:16 -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="o/TREYCp"; 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 S2388734AbfIDSFD (ORCPT + 99 others); Wed, 4 Sep 2019 14:05:03 -0400 Received: from mail.kernel.org ([198.145.29.99]:46240 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S2389184AbfIDSFA (ORCPT ); Wed, 4 Sep 2019 14:05:00 -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 4B969208E4; Wed, 4 Sep 2019 18:04:59 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1567620299; bh=rQzTqad7vYVA9aEKCauaJxkfbmis2wcKr2tEhpPOAME=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=o/TREYCpyE/hgHfxeUZohrhdkq5VStTnYtxI4DN7qaZxt1jN8cZqk99DbQaTkmw4f U7u/TWIWHiukVGRd+7sU06ORP9Rr4q9vgv1vl0htqtSEOxt0RBOuwxHz3m3yydIDr5 ZhKV8vSNqyxkfypoLYWJ4YX5U0LQ8Rli/QRTC/ew= 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 , Sasha Levin Subject: [PATCH 4.14 50/57] KVM: arm/arm64: vgic: Fix potential deadlock when ap_list is long Date: Wed, 4 Sep 2019 19:54:18 +0200 Message-Id: <20190904175306.782871082@linuxfoundation.org> X-Mailer: git-send-email 2.23.0 In-Reply-To: <20190904175301.777414715@linuxfoundation.org> References: <20190904175301.777414715@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 [ Upstream commit d4a8061a7c5f7c27a2dc002ee4cb89b3e6637e44 ] 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: Sasha Levin --- virt/kvm/arm/vgic/vgic.c | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/virt/kvm/arm/vgic/vgic.c b/virt/kvm/arm/vgic/vgic.c index 9d4e01f109499..07ee8e4e00a21 100644 --- a/virt/kvm/arm/vgic/vgic.c +++ b/virt/kvm/arm/vgic/vgic.c @@ -199,6 +199,13 @@ static int vgic_irq_cmp(void *priv, struct list_head *a, struct list_head *b) 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; + spin_lock(&irqa->irq_lock); spin_lock_nested(&irqb->irq_lock, SINGLE_DEPTH_NESTING); -- 2.20.1