Received: by 2002:ad5:474a:0:0:0:0:0 with SMTP id i10csp3525449imu; Mon, 7 Jan 2019 05:05:50 -0800 (PST) X-Google-Smtp-Source: ALg8bN4QbA/VuNVS09fdWx1BYuggY5pxCObIqwyW/eTMh/fAxJp3yMGWV36acklPt9wZpcUXPayj X-Received: by 2002:a17:902:7c85:: with SMTP id y5mr60869774pll.63.1546866350206; Mon, 07 Jan 2019 05:05:50 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1546866350; cv=none; d=google.com; s=arc-20160816; b=WriHjh1mixLD14TiJ9LCV1BH94OKUb+qiOQjhjLvhdP9FyIA3Zs7ObIHERPgfs3ejT reZMgkfKaoZ7pooZUfzLeopV6sASGn2ZuFFLTWE3sBvXQrtPMNsODlmGdVagMRb/HXWN ne8qcllVkK2wKzkYgpgx5cK4K8IHt0CccqJ1cD2eqvt6xWH+1BxmbCN064WdC/XmKM0G PNIq75KVT0X2Lv074qUosry7/wf38+nAqGdi6DNnIqBA7eGBjPP3d+u4KD+tuKE6xOXX 47waO9lDDjV44552193BMFpAK1UxBkNIm99natOuWdHs4L9NH/Py+vY5IY1nD5kuAYPd BAtw== 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=/foW7NH2xFLKlZnbM/4jubOZL3LVhkiTizRyB6UXH+0=; b=VHV4Bv5UcM/HzlGUV84y/D6e11m+Myko2cp3pBNjAIdxZqZN04kXmr44yvTyum8VIL iC9T9YtlXcBrisjC5tHRDLk3ikFwgI9pOXzMOjA1HAM0DioTaFZa+yeGhiiWAdvQZhre 2hYp61Y8cTVfwzbEAn5MqlndswDY5LZoVdESrsMaa/xkGfaP2kEqklgwOnAjBj5cIZI5 2ZVXSYnXeuY5fHVExjGg+mhZDdIssnYWQM4unUTOZsZrBZuF0141d5KBe9HrObMbAH4m 1BQ1hJ6nn4G+0Fbjaaq0vhgic2M+A7zZCx2YI8xQxVd8z4tElVg+osjNlKArS6Wihx5n /+eQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=lMM0LnHX; 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 b131si48883187pga.394.2019.01.07.05.05.34; Mon, 07 Jan 2019 05:05:50 -0800 (PST) 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=lMM0LnHX; 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 S1730806AbfAGNC1 (ORCPT + 99 others); Mon, 7 Jan 2019 08:02:27 -0500 Received: from mail.kernel.org ([198.145.29.99]:49934 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1730798AbfAGNCZ (ORCPT ); Mon, 7 Jan 2019 08:02:25 -0500 Received: from localhost (5356596B.cm-6-7b.dynamic.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 11CCE2089F; Mon, 7 Jan 2019 13:02:23 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1546866144; bh=YOG7hbAdiB4UAtBKl5zJrEL3SwV7EKxnTdWp1TihnLE=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=lMM0LnHXR/s5AiOjKKj0C+5uLO9y2wSGH8mffZ8KEOcM4Vf6cF0qLHyUF9Xs9XHUT XuLi93PKx2ZkRzR/BPSW/haWxavNnYi3Ic1cELKIcvDrycwGC3jHfWBILq3lVjdLQV AwES16jlVrEDpylCG4rSGNjKsfgSdM0xIA4Jndx0= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Miquel Raynal , Marc Zyngier Subject: [PATCH 4.14 060/101] platform-msi: Free descriptors in platform_msi_domain_free() Date: Mon, 7 Jan 2019 13:32:48 +0100 Message-Id: <20190107105336.206881509@linuxfoundation.org> X-Mailer: git-send-email 2.20.1 In-Reply-To: <20190107105330.372621917@linuxfoundation.org> References: <20190107105330.372621917@linuxfoundation.org> User-Agent: quilt/0.65 X-stable: review X-Patchwork-Hint: ignore 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 4.14-stable review patch. If anyone has any objections, please let me know. ------------------ From: Miquel Raynal commit 81b1e6e6a8590a19257e37a1633bec098d499c57 upstream. Since the addition of platform MSI support, there were two helpers supposed to allocate/free IRQs for a device: platform_msi_domain_alloc_irqs() platform_msi_domain_free_irqs() In these helpers, IRQ descriptors are allocated in the "alloc" routine while they are freed in the "free" one. Later, two other helpers have been added to handle IRQ domains on top of MSI domains: platform_msi_domain_alloc() platform_msi_domain_free() Seen from the outside, the logic is pretty close with the former helpers and people used it with the same logic as before: a platform_msi_domain_alloc() call should be balanced with a platform_msi_domain_free() call. While this is probably what was intended to do, the platform_msi_domain_free() does not remove/free the IRQ descriptor(s) created/inserted in platform_msi_domain_alloc(). One effect of such situation is that removing a module that requested an IRQ will let one orphaned IRQ descriptor (with an allocated MSI entry) in the device descriptors list. Next time the module will be inserted back, one will observe that the allocation will happen twice in the MSI domain, one time for the remaining descriptor, one time for the new one. It also has the side effect to quickly overshoot the maximum number of allocated MSI and then prevent any module requesting an interrupt in the same domain to be inserted anymore. This situation has been met with loops of insertion/removal of the mvpp2.ko module (requesting 15 MSIs each time). Fixes: 552c494a7666 ("platform-msi: Allow creation of a MSI-based stacked irq domain") Cc: stable@vger.kernel.org Signed-off-by: Miquel Raynal Signed-off-by: Marc Zyngier Signed-off-by: Greg Kroah-Hartman --- drivers/base/platform-msi.c | 6 ++++-- include/linux/msi.h | 2 ++ 2 files changed, 6 insertions(+), 2 deletions(-) --- a/drivers/base/platform-msi.c +++ b/drivers/base/platform-msi.c @@ -374,14 +374,16 @@ void platform_msi_domain_free(struct irq unsigned int nvec) { struct platform_msi_priv_data *data = domain->host_data; - struct msi_desc *desc; - for_each_msi_entry(desc, data->dev) { + struct msi_desc *desc, *tmp; + for_each_msi_entry_safe(desc, tmp, data->dev) { if (WARN_ON(!desc->irq || desc->nvec_used != 1)) return; if (!(desc->irq >= virq && desc->irq < (virq + nvec))) continue; irq_domain_free_irqs_common(domain, desc->irq, 1); + list_del(&desc->list); + free_msi_entry(desc); } } --- a/include/linux/msi.h +++ b/include/linux/msi.h @@ -116,6 +116,8 @@ struct msi_desc { list_first_entry(dev_to_msi_list((dev)), struct msi_desc, list) #define for_each_msi_entry(desc, dev) \ list_for_each_entry((desc), dev_to_msi_list((dev)), list) +#define for_each_msi_entry_safe(desc, tmp, dev) \ + list_for_each_entry_safe((desc), (tmp), dev_to_msi_list((dev)), list) #ifdef CONFIG_PCI_MSI #define first_pci_msi_entry(pdev) first_msi_entry(&(pdev)->dev)