Received: by 2002:ad5:474a:0:0:0:0:0 with SMTP id i10csp3436195imu; Sun, 11 Nov 2018 15:04:00 -0800 (PST) X-Google-Smtp-Source: AJdET5chpSruRTForTVKO4HtGmkvfw9xWe6l1TBcSCxY3B77IVaaDtRKo0OAAMA7tb/6s77nvGFL X-Received: by 2002:a63:f047:: with SMTP id s7mr15306225pgj.441.1541977440657; Sun, 11 Nov 2018 15:04:00 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1541977440; cv=none; d=google.com; s=arc-20160816; b=YwoVYI0ro4p8oJKslIOOTNbHLQbAQUKbH3bWxs7IXVkU27h19Jy+IrXSg2gaeVQ6JE pNshVdDeKEPANEqMfFOSnyWJHkI30QDFUDXEza2A/CMVnPUREGMliyJVChK25poTMBM0 lPg+YBODyTYLutUGZO/CMpsQXmLlax/uqQpKDQyWhXVfYpjlB/l6vU7ymEpcdzxSvouo HeI1+OrqNl24KUXBtCGR3i3wRmuOCaINTQroNdfvqOGxWRtqBuWlx1TpcrXbqmPjPwfz bIk8mPLP2z8SU1/+bgeB5ykpC8EvOwPP22IFSjb/0wMYcxlCGoNByXrsVD0HQRYx72U6 ocaQ== 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=oX1W8YszXkMM59pnqaWVDFEpN+0f47r1R0Dqh20Jnjc=; b=D64hcm2T4bh/iJLkSMRjF6HgfnZjucKrqNx7j0hhxPHlvcGCm3wvUCE9+HASGA6xbU AI5kpyqPry/g51n2ozNbWagxvSD1/A4Ih72d3DdG6Vg4gY0aiBI23nzzeau0iS4q/fUU QOgrbS9y2x9ZWgKbYmNeVOYydGZj6RST4NtSr0xalwqrDU2bRB/+FC3QklzCoevy25LI qxDg6Z0n6ZaNZIaJTTji98jyW2DQJ3oyMLEhtOnOTZo3PBIX7DwCrR5qAwowL7cq5fOl pHt32iwP0ndgsyzAD370Zxa00/5KAWnD8zbE2r4pTlNvADjtqxmXkdlxZ5lJTlqmpGz/ 8r9A== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=CzZDherA; 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 e39-v6si15485778plg.366.2018.11.11.15.03.45; Sun, 11 Nov 2018 15:04:00 -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=CzZDherA; 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 S2388766AbeKLIwT (ORCPT + 99 others); Mon, 12 Nov 2018 03:52:19 -0500 Received: from mail.kernel.org ([198.145.29.99]:51248 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S2390632AbeKLIW3 (ORCPT ); Mon, 12 Nov 2018 03:22:29 -0500 Received: from localhost (unknown [206.108.79.134]) (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 E79FF223C8; Sun, 11 Nov 2018 22:32:31 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1541975552; bh=TdUL3f4ZnQXiBnUF/vYXUnasufPZnLV+dDvdw1oYLAM=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=CzZDherAdBl55PlEcG8KMcnlGxVLEu7TG36QiMZmdrt09Hnhz7WNCtahdWME+uzcg gjnRI1jg3sYlQlsMevcGKMlMhDIb9VJCGenXSLKzVqNkgFUHtx0gb5TsCVZMh925xT 7EcNqo2l7fSnG12vndEqyrGWlC53119mxE2Q3fb0= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Tonghao Zhang , Bjorn Helgaas , Sasha Levin Subject: [PATCH 4.14 094/222] PCI/MSI: Warn and return error if driver enables MSI/MSI-X twice Date: Sun, 11 Nov 2018 14:23:11 -0800 Message-Id: <20181111221656.357476112@linuxfoundation.org> X-Mailer: git-send-email 2.19.1 In-Reply-To: <20181111221647.665769131@linuxfoundation.org> References: <20181111221647.665769131@linuxfoundation.org> User-Agent: quilt/0.65 X-stable: review 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: Tonghao Zhang [ Upstream commit 4c1ef72e9b71a19fb405ebfcd37c0a5e16fa44ca ] It is a serious driver defect to enable MSI or MSI-X more than once. Doing so may panic the kernel as in the stack trace below: Call Trace: sysfs_add_one+0xa5/0xd0 create_dir+0x7c/0xe0 sysfs_create_subdir+0x1c/0x20 internal_create_group+0x6d/0x290 sysfs_create_groups+0x4a/0xa0 populate_msi_sysfs+0x1cd/0x210 pci_enable_msix+0x31c/0x3e0 igbuio_pci_open+0x72/0x300 [igb_uio] uio_open+0xcc/0x120 [uio] chrdev_open+0xa1/0x1e0 [...] do_sys_open+0xf3/0x1f0 SyS_open+0x1e/0x20 system_call_fastpath+0x16/0x1b ---[ end trace 11042e2848880209 ]--- Kernel panic - not syncing: stack-protector: Kernel stack is corrupted in: ffffffffa056b4fa We want to keep the WARN_ON() and stack trace so the driver can be fixed, but we can avoid the kernel panic by returning an error. We may still get warnings like this: Call Trace: pci_enable_msix+0x3c9/0x3e0 igbuio_pci_open+0x72/0x300 [igb_uio] uio_open+0xcc/0x120 [uio] chrdev_open+0xa1/0x1e0 [...] do_sys_open+0xf3/0x1f0 SyS_open+0x1e/0x20 system_call_fastpath+0x16/0x1b ------------[ cut here ]------------ WARNING: at fs/sysfs/dir.c:526 sysfs_add_one+0xa5/0xd0() sysfs: cannot create duplicate filename '/devices/pci0000:00/0000:00:03.0/0000:01:00.1/msi_irqs' Signed-off-by: Tonghao Zhang [bhelgaas: changelog, fix patch whitespace, remove !!] Signed-off-by: Bjorn Helgaas Signed-off-by: Sasha Levin Signed-off-by: Greg Kroah-Hartman --- drivers/pci/msi.c | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) --- a/drivers/pci/msi.c +++ b/drivers/pci/msi.c @@ -958,7 +958,6 @@ static int __pci_enable_msix(struct pci_ } } } - WARN_ON(!!dev->msix_enabled); /* Check whether driver already requested for MSI irq */ if (dev->msi_enabled) { @@ -1028,8 +1027,6 @@ static int __pci_enable_msi_range(struct if (!pci_msi_supported(dev, minvec)) return -EINVAL; - WARN_ON(!!dev->msi_enabled); - /* Check whether driver already requested MSI-X irqs */ if (dev->msix_enabled) { dev_info(&dev->dev, @@ -1040,6 +1037,9 @@ static int __pci_enable_msi_range(struct if (maxvec < minvec) return -ERANGE; + if (WARN_ON_ONCE(dev->msi_enabled)) + return -EINVAL; + nvec = pci_msi_vec_count(dev); if (nvec < 0) return nvec; @@ -1088,6 +1088,9 @@ static int __pci_enable_msix_range(struc if (maxvec < minvec) return -ERANGE; + if (WARN_ON_ONCE(dev->msix_enabled)) + return -EINVAL; + for (;;) { if (affd) { nvec = irq_calc_affinity_vectors(minvec, nvec, affd);