From owner-svn-src-all@freebsd.org Wed Nov 14 18:45:35 2018 Return-Path: Delivered-To: svn-src-all@mailman.ysv.freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2610:1c1:1:606c::19:1]) by mailman.ysv.freebsd.org (Postfix) with ESMTP id F08A611313CA; Wed, 14 Nov 2018 18:45:34 +0000 (UTC) (envelope-from jhb@FreeBSD.org) Received: from mxrelay.nyi.freebsd.org (mxrelay.nyi.freebsd.org [IPv6:2610:1c1:1:606c::19:3]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (Client CN "mxrelay.nyi.freebsd.org", Issuer "Let's Encrypt Authority X3" (verified OK)) by mx1.freebsd.org (Postfix) with ESMTPS id 80EEE84C34; Wed, 14 Nov 2018 18:45:34 +0000 (UTC) (envelope-from jhb@FreeBSD.org) Received: from repo.freebsd.org (repo.freebsd.org [IPv6:2610:1c1:1:6068::e6a:0]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (Client did not present a certificate) by mxrelay.nyi.freebsd.org (Postfix) with ESMTPS id 6211122E93; Wed, 14 Nov 2018 18:45:34 +0000 (UTC) (envelope-from jhb@FreeBSD.org) Received: from repo.freebsd.org ([127.0.1.37]) by repo.freebsd.org (8.15.2/8.15.2) with ESMTP id wAEIjYmd075338; Wed, 14 Nov 2018 18:45:34 GMT (envelope-from jhb@FreeBSD.org) Received: (from jhb@localhost) by repo.freebsd.org (8.15.2/8.15.2/Submit) id wAEIjYwP075337; Wed, 14 Nov 2018 18:45:34 GMT (envelope-from jhb@FreeBSD.org) Message-Id: <201811141845.wAEIjYwP075337@repo.freebsd.org> X-Authentication-Warning: repo.freebsd.org: jhb set sender to jhb@FreeBSD.org using -f From: John Baldwin Date: Wed, 14 Nov 2018 18:45:34 +0000 (UTC) To: src-committers@freebsd.org, svn-src-all@freebsd.org, svn-src-head@freebsd.org Subject: svn commit: r340441 - head/sys/x86/x86 X-SVN-Group: head X-SVN-Commit-Author: jhb X-SVN-Commit-Paths: head/sys/x86/x86 X-SVN-Commit-Revision: 340441 X-SVN-Commit-Repository: base MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit X-Rspamd-Queue-Id: 80EEE84C34 X-Spamd-Result: default: False [-106.88 / 200.00]; ARC_NA(0.00)[]; NEURAL_HAM_MEDIUM(-1.00)[-1.000,0]; ALLOW_DOMAIN_WHITELIST(-100.00)[FreeBSD.org]; FROM_HAS_DN(0.00)[]; RCPT_COUNT_THREE(0.00)[3]; TO_MATCH_ENVRCPT_ALL(0.00)[]; NEURAL_HAM_LONG(-1.00)[-1.000,0]; MIME_GOOD(-0.10)[text/plain]; TO_DN_NONE(0.00)[]; HAS_XAW(0.00)[]; R_SPF_SOFTFAIL(0.00)[~all]; DMARC_NA(0.00)[FreeBSD.org]; RCVD_COUNT_THREE(0.00)[4]; MX_GOOD(-0.01)[cached: mx1.FreeBSD.org]; NEURAL_HAM_SHORT(-1.00)[-0.999,0]; FROM_EQ_ENVFROM(0.00)[]; R_DKIM_NA(0.00)[]; RCVD_TLS_LAST(0.00)[]; ASN(0.00)[asn:11403, ipnet:2610:1c1:1::/48, country:US]; IP_SCORE(-3.77)[ip: (-9.91), ipnet: 2610:1c1:1::/48(-4.93), asn: 11403(-3.91), country: US(-0.10)] X-Rspamd-Server: mx1.freebsd.org X-BeenThere: svn-src-all@freebsd.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: "SVN commit messages for the entire src tree \(except for " user" and " projects" \)" List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Wed, 14 Nov 2018 18:45:35 -0000 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. */