Received: by 2002:ad5:474a:0:0:0:0:0 with SMTP id i10csp3481014imu; Sun, 11 Nov 2018 16:04:58 -0800 (PST) X-Google-Smtp-Source: AJdET5f0/mp7eL/2g2io5ZDcKwm3m4kkRUOSTqHefxwsJS+vPGQYoJQga43g5TV/Mdy0Mtx8iOM9 X-Received: by 2002:a62:cac4:: with SMTP id y65-v6mr17932950pfk.27.1541981098190; Sun, 11 Nov 2018 16:04:58 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1541981098; cv=none; d=google.com; s=arc-20160816; b=S7UKOSGRhPwwfNLQolXNZdTpAC4OdlfmO/05N6mQZNWCpNmyQt9zdMXu9g8E20blxk QuczX1wrH9+RMfm2ulI/tja2b6Ww+KDUGJJMlwtFNs40X8TS22WbvrKkwqQfrlysjqO0 DbrG4wKfuLlKs7yhFCg+BZXSGYgFrm2DWDg7hWutaMqknfvYKxnkQQV8FWvh9k2d9iSc vOMtFIKPVZoYNlxPeLZLfGSbQ5256PrJnZz4LhgTPb8k/g80/1AUoRGVthptOHBOAFGv JfZLhMZUK8Xqt2Wd43wYniGvyZV2nBPgY9LBoPIgGrdo59iXzNRDKmwdYzCbnFqwLJT7 rTfA== 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=ce3+snXnVFVY8Q2kR7sfXApaDU8NkVzBhF0KPQ0Q7/w=; b=tdI77FBL3uVhgQd+nWZB3/ebw02WI091AAdcQChVLunLC+Ex8mV5eh3cUrtisWoLwt InOd6nph8IFdecAxKN92hGVgRiXeE5hm7XNuvmXC2w1StrjRpXvk8WAEw+SyjYLh3fA1 ZFlXXbuTvkKVCZOR7evP8wj43t/jtB6pFb5m+sLikpyEXYzzpxBjWfvi5aQ1XDfdkeTm Pzj/pRondP49zBZR+FfBSbbfCo4uW6YP62TSAo3xtQZMRmaQ01P5S1q/mLOXg1YQSho8 6W+iy1fXLK168HpYNooD2GawUPscwMo2fjOm4V+saEKT4PHkP3ifDLzhI96HS1vI41rL 6eHA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=XU8dc14v; 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 s192si15058422pgc.144.2018.11.11.16.04.43; Sun, 11 Nov 2018 16:04:58 -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=XU8dc14v; 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 S1732049AbeKLIRr (ORCPT + 99 others); Mon, 12 Nov 2018 03:17:47 -0500 Received: from mail.kernel.org ([198.145.29.99]:34412 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1729476AbeKLIRq (ORCPT ); Mon, 12 Nov 2018 03:17:46 -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 E30EB21582; Sun, 11 Nov 2018 22:27:50 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1541975270; bh=d/6UFrNa09IIUn5ynQKof5md+F5RdpuDUc9YeHs9y+4=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=XU8dc14vBTPHJOtIlg/hDEXxvW3FIevpmaBxPtl+JhhRvxxMwcgPz0W7hWgDSgH7g wHQeN9r7aFtXCFCBcxf3A1Ik9A8NQSEjTuNdOjl25MZWZL6jjeyCgAI617PxVt8u9K l2P3o7WbOKp8hqTHwnC785Naugfq8N7lRJfdi9KI= 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.19 169/361] PCI/MSI: Warn and return error if driver enables MSI/MSI-X twice Date: Sun, 11 Nov 2018 14:18:36 -0800 Message-Id: <20181111221644.054759569@linuxfoundation.org> X-Mailer: git-send-email 2.19.1 In-Reply-To: <20181111221619.915519183@linuxfoundation.org> References: <20181111221619.915519183@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.19-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) { pci_info(dev, "can't enable MSI (MSI-X already enabled)\n"); @@ -1039,6 +1036,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; @@ -1087,6 +1087,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);