Skip site navigation (1)Skip section navigation (2)
Date:      Sat, 29 Dec 2018 01:19:14 +0000 (UTC)
From:      John Baldwin <jhb@FreeBSD.org>
To:        src-committers@freebsd.org, svn-src-all@freebsd.org, svn-src-stable@freebsd.org, svn-src-stable-12@freebsd.org
Subject:   svn commit: r342587 - in stable: 10/sys/x86/x86 11/sys/x86/x86 12/sys/x86/x86
Message-ID:  <201812290119.wBT1JEH6030710@repo.freebsd.org>

next in thread | raw e-mail | index | archive | help
Author: jhb
Date: Sat Dec 29 01:19:14 2018
New Revision: 342587
URL: https://svnweb.freebsd.org/changeset/base/342587

Log:
  MFC 340441: Revert r332735 and fix MSI-X to properly fail allocations when full.
  
  The off-by-one errors in 332735 weren't actual errors and were
  preventing the last MSI interrupt source from being used.  Instead,
  the issue is that when all MSI interrupt sources were allocated, the
  loop in msix_alloc() would terminate with 'msi' still set to non-null.
  The only check for 'i' overflowing was in the 'msi' == NULL case, so
  msix_alloc() would try to reuse the last MSI interrupt source instead
  of failing.
  
  Fix by moving the check for all sources being in use to just after the
  loop.

Modified:
  stable/12/sys/x86/x86/msi.c
Directory Properties:
  stable/12/   (props changed)

Changes in other areas also in this revision:
Modified:
  stable/10/sys/x86/x86/msi.c
  stable/11/sys/x86/x86/msi.c
Directory Properties:
  stable/10/   (props changed)
  stable/11/   (props changed)

Modified: stable/12/sys/x86/x86/msi.c
==============================================================================
--- stable/12/sys/x86/x86/msi.c	Sat Dec 29 00:44:11 2018	(r342586)
+++ stable/12/sys/x86/x86/msi.c	Sat Dec 29 01:19:14 2018	(r342587)
@@ -409,7 +409,7 @@ again:
 	/* Do we need to create some new sources? */
 	if (cnt < count) {
 		/* If we would exceed the max, give up. */
-		if (i + (count - cnt) >= first_msi_irq + NUM_MSI_INTS) {
+		if (i + (count - cnt) > first_msi_irq + NUM_MSI_INTS) {
 			mtx_unlock(&msi_lock);
 			free(mirqs, M_MSI);
 			return (ENXIO);
@@ -647,13 +647,14 @@ again:
 			break;
 	}
 
+	/* Are all IRQs in use? */
+	if (i == first_msi_irq + NUM_MSI_INTS) {
+		mtx_unlock(&msi_lock);
+		return (ENXIO);
+	}
+
 	/* Do we need to create a new source? */
 	if (msi == NULL) {
-		/* If we would exceed the max, give up. */
-		if (i + 1 >= first_msi_irq + NUM_MSI_INTS) {
-			mtx_unlock(&msi_lock);
-			return (ENXIO);
-		}
 		mtx_unlock(&msi_lock);
 
 		/* Create a new source. */



Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?201812290119.wBT1JEH6030710>