svn commit: r340441 - head/sys/x86/x86

John Baldwin jhb at FreeBSD.org
Wed Nov 14 18:45:35 UTC 2018


Author: jhb
Date: Wed Nov 14 18:45:33 2018
New Revision: 340441
URL: https://svnweb.freebsd.org/changeset/base/340441

Log:
  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.
  
  Reviewed by:	kib, markj
  MFC after:	1 month
  Differential Revision:	https://reviews.freebsd.org/D17976

Modified:
  head/sys/x86/x86/msi.c

Modified: head/sys/x86/x86/msi.c
==============================================================================
--- head/sys/x86/x86/msi.c	Wed Nov 14 18:38:27 2018	(r340440)
+++ head/sys/x86/x86/msi.c	Wed Nov 14 18:45:33 2018	(r340441)
@@ -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. */


More information about the svn-src-all mailing list