Received: by 2002:ac0:98c7:0:0:0:0:0 with SMTP id g7-v6csp170783imd; Wed, 31 Oct 2018 16:44:54 -0700 (PDT) X-Google-Smtp-Source: AJdET5f9K/BNClRId9AOiBLE4DTzC9AOUook8gXbaxi+lZENUk2ihHvj7iYsgGfrm4qzqC0QUTSt X-Received: by 2002:a63:1919:: with SMTP id z25-v6mr4905160pgl.135.1541029494486; Wed, 31 Oct 2018 16:44:54 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1541029494; cv=none; d=google.com; s=arc-20160816; b=mVkELVMy3dW3nAft5HV307iYSmOZzLmNwMG4Nrohd+SZf15wWQDQljcm08YiSoLhAR Ks4bMReb3z+sEJSxmUKEgL8QLv+MUSlu1od5ybH9XVkw27jpo07xSQdcR62Sjva5bSe/ nfElpb9MEi1e4EjA9cAbQDNxoNTxl4lF4AqVd2B0N4uo2QJT2KQK2TqTbmWtLERdJgcD YefnU2VBqgoVD/s2I0sQBHj2MBIk5kjOHM/RWaVvTFjlJtYGg0Pcxdj94ONj1adSOI/h RMBzCRl1cK42idBkputMvdtxvc2GRvd9okOTgYyT3BRC7/ykckAprcbaPfzMv7eRtHaC moKQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:references:in-reply-to:message-id:date :subject:cc:to:from:dkim-signature; bh=8CJk0XImAq68LcUJhuAwPib0hBjURf50P45IT6W82Fw=; b=jDJNYbYYgFlbPDQqLrqtQSoM0022wcY+gy0G2EKRD5jgG7vO/hiIlWyBfJwHXOHuyG dfqplFbgg0wb6rB4qN4idwW/VPbwiOHX5HNJ4BjtY6iVDk4C9lFrbbL2sb2xNn/eiYfB PwQ2M0XvQFmb35sh6nJWLXm0BmfvfjDuGDe6H7ilI76x3TF4eOvj43uexN9sEOPHl5Ja Xl6UNwixNWi1YRGOhKmn5eMhEQwsLa25EMoz3dbDAtf83F1wNV/BFrWrD89Swz07rNe/ RpFqm8J4Cli/SyYnF2UQTGMNECkQQ8zEYFGViDgOKGhQ9n9SrJ8t9K9qEK5jyPPvgvZl w0Pw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=NdnxMzqf; 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; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id g14-v6si20678594pgf.10.2018.10.31.16.44.39; Wed, 31 Oct 2018 16:44:54 -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=NdnxMzqf; 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; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1729184AbeKAIHs (ORCPT + 99 others); Thu, 1 Nov 2018 04:07:48 -0400 Received: from mail.kernel.org ([198.145.29.99]:55832 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1729150AbeKAIHq (ORCPT ); Thu, 1 Nov 2018 04:07:46 -0400 Received: from sasha-vm.mshome.net (c-73-47-72-35.hsd1.nh.comcast.net [73.47.72.35]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPSA id 5976320843; Wed, 31 Oct 2018 23:07:34 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1541027254; bh=HzSE0Lu1QeuI6M4yrX3S9kW18enyNOcN4OQqac9Fw64=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=NdnxMzqfON8+KcVdjcUF486lCjvdPglOCbQLa94xP4f2sgi+c72+nSHco2d3erGiS NkOdc2qZMEchTMXKPAQzPDQb3HdCh0McYAXZZ9u9Ock7adg8GAuepGqjitWQbB397a TWX0OBTprE8u1GE/PrsSCj1wBDnuY7CNytQ3/udM= From: Sasha Levin To: stable@vger.kernel.org, linux-kernel@vger.kernel.org Cc: Tonghao Zhang , Bjorn Helgaas , Sasha Levin Subject: [PATCH AUTOSEL 4.19 125/146] PCI/MSI: Warn and return error if driver enables MSI/MSI-X twice Date: Wed, 31 Oct 2018 19:05:20 -0400 Message-Id: <20181031230541.28822-125-sashal@kernel.org> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20181031230541.28822-1-sashal@kernel.org> References: <20181031230541.28822-1-sashal@kernel.org> Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org 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 --- drivers/pci/msi.c | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/drivers/pci/msi.c b/drivers/pci/msi.c index f2ef896464b3..af24ed50a245 100644 --- a/drivers/pci/msi.c +++ b/drivers/pci/msi.c @@ -958,7 +958,6 @@ static int __pci_enable_msix(struct pci_dev *dev, struct msix_entry *entries, } } } - 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 pci_dev *dev, int minvec, int maxvec, 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 pci_dev *dev, int minvec, int maxvec, 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(struct pci_dev *dev, 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); -- 2.17.1