From owner-svn-src-all@freebsd.org Thu Nov 15 18:37:43 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 5876E1105E80; Thu, 15 Nov 2018 18:37:43 +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 D7B2377D0A; Thu, 15 Nov 2018 18:37:42 +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 B825C12332; Thu, 15 Nov 2018 18:37:42 +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 wAFIbgPl018445; Thu, 15 Nov 2018 18:37:42 GMT (envelope-from jhb@FreeBSD.org) Received: (from jhb@localhost) by repo.freebsd.org (8.15.2/8.15.2/Submit) id wAFIbgVN018442; Thu, 15 Nov 2018 18:37:42 GMT (envelope-from jhb@FreeBSD.org) Message-Id: <201811151837.wAFIbgVN018442@repo.freebsd.org> X-Authentication-Warning: repo.freebsd.org: jhb set sender to jhb@FreeBSD.org using -f From: John Baldwin Date: Thu, 15 Nov 2018 18:37:42 +0000 (UTC) To: src-committers@freebsd.org, svn-src-all@freebsd.org, svn-src-head@freebsd.org Subject: svn commit: r340460 - in head/sys/x86: include x86 xen X-SVN-Group: head X-SVN-Commit-Author: jhb X-SVN-Commit-Paths: in head/sys/x86: include x86 xen X-SVN-Commit-Revision: 340460 X-SVN-Commit-Repository: base MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit X-Rspamd-Queue-Id: D7B2377D0A 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)[-1.000,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: Thu, 15 Nov 2018 18:37:43 -0000 Author: jhb Date: Thu Nov 15 18:37:41 2018 New Revision: 340460 URL: https://svnweb.freebsd.org/changeset/base/340460 Log: Convert the number of MSI IRQs on x86 from a constant to a tunable. The number of MSI IRQs still defaults to 512, but it can now be changed at boot time via the machdep.num_msi_irqs tunable. Reviewed by: kib, royger (older version) Reviewed by: markj MFC after: 1 month Relnotes: yes Differential Revision: https://reviews.freebsd.org/D17977 Modified: head/sys/x86/include/intr_machdep.h head/sys/x86/x86/msi.c head/sys/x86/xen/xen_intr.c head/sys/x86/xen/xen_msi.c Modified: head/sys/x86/include/intr_machdep.h ============================================================================== --- head/sys/x86/include/intr_machdep.h Thu Nov 15 17:25:32 2018 (r340459) +++ head/sys/x86/include/intr_machdep.h Thu Nov 15 18:37:41 2018 (r340460) @@ -58,11 +58,11 @@ * the minimum IRQ value for MSI interrupts to attempt to leave 255 * unused since 255 is used in PCI to indicate an invalid INTx IRQ. */ -#define NUM_MSI_INTS 512 #define MINIMUM_MSI_INT 256 extern u_int first_msi_irq; extern u_int num_io_irqs; +extern u_int num_msi_irqs; /* * Default base address for MSI messages on x86 platforms. Modified: head/sys/x86/x86/msi.c ============================================================================== --- head/sys/x86/x86/msi.c Thu Nov 15 17:25:32 2018 (r340459) +++ head/sys/x86/x86/msi.c Thu Nov 15 18:37:41 2018 (r340460) @@ -44,6 +44,7 @@ __FBSDID("$FreeBSD$"); #include #include #include +#include #include #include #include @@ -153,6 +154,10 @@ struct pic msi_pic = { u_int first_msi_irq; +u_int num_msi_irqs = 512; +SYSCTL_UINT(_machdep, OID_AUTO, num_msi_irqs, CTLFLAG_RDTUN, &num_msi_irqs, 0, + "Number of IRQs reserved for MSI and MSI-X interrupts"); + #ifdef SMP /** * Xen hypervisors prior to 4.6.0 do not properly handle updates to @@ -331,8 +336,13 @@ msi_init(void) } #endif + if (num_msi_irqs == 0) + return; + first_msi_irq = max(MINIMUM_MSI_INT, num_io_irqs); - num_io_irqs = first_msi_irq + NUM_MSI_INTS; + if (num_msi_irqs > UINT_MAX - first_msi_irq) + panic("num_msi_irq too high"); + num_io_irqs = first_msi_irq + num_msi_irqs; msi_enabled = 1; intr_register_pic(&msi_pic); @@ -346,7 +356,7 @@ msi_create_source(void) u_int irq; mtx_lock(&msi_lock); - if (msi_last_irq >= NUM_MSI_INTS) { + if (msi_last_irq >= num_msi_irqs) { mtx_unlock(&msi_lock); return; } @@ -390,7 +400,7 @@ again: /* Try to find 'count' free IRQs. */ cnt = 0; - for (i = first_msi_irq; i < first_msi_irq + NUM_MSI_INTS; i++) { + for (i = first_msi_irq; i < first_msi_irq + num_msi_irqs; i++) { msi = (struct msi_intsrc *)intr_lookup_source(i); /* End of allocated sources, so break. */ @@ -409,7 +419,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_irqs) { mtx_unlock(&msi_lock); free(mirqs, M_MSI); return (ENXIO); @@ -585,7 +595,7 @@ msi_map(int irq, uint64_t *addr, uint32_t *data) #ifdef ACPI_DMAR if (!msi->msi_msix) { for (k = msi->msi_count - 1, i = first_msi_irq; k > 0 && - i < first_msi_irq + NUM_MSI_INTS; i++) { + i < first_msi_irq + num_msi_irqs; i++) { if (i == msi->msi_irq) continue; msi1 = (struct msi_intsrc *)intr_lookup_source(i); @@ -635,7 +645,7 @@ again: mtx_lock(&msi_lock); /* Find a free IRQ. */ - for (i = first_msi_irq; i < first_msi_irq + NUM_MSI_INTS; i++) { + for (i = first_msi_irq; i < first_msi_irq + num_msi_irqs; i++) { msi = (struct msi_intsrc *)intr_lookup_source(i); /* End of allocated sources, so break. */ @@ -648,7 +658,7 @@ again: } /* Are all IRQs in use? */ - if (i == first_msi_irq + NUM_MSI_INTS) { + if (i == first_msi_irq + num_msi_irqs) { mtx_unlock(&msi_lock); return (ENXIO); } Modified: head/sys/x86/xen/xen_intr.c ============================================================================== --- head/sys/x86/xen/xen_intr.c Thu Nov 15 17:25:32 2018 (r340459) +++ head/sys/x86/xen/xen_intr.c Thu Nov 15 18:37:41 2018 (r340460) @@ -690,6 +690,8 @@ void xen_intr_alloc_irqs(void) { + if (num_io_irqs > UINT_MAX - NR_EVENT_CHANNELS) + panic("IRQ allocation overflow (num_msi_irqs too high?)"); first_evtchn_irq = num_io_irqs; num_io_irqs += NR_EVENT_CHANNELS; } Modified: head/sys/x86/xen/xen_msi.c ============================================================================== --- head/sys/x86/xen/xen_msi.c Thu Nov 15 17:25:32 2018 (r340459) +++ head/sys/x86/xen/xen_msi.c Thu Nov 15 18:37:41 2018 (r340460) @@ -30,6 +30,7 @@ __FBSDID("$FreeBSD$"); #include #include #include +#include #include #include #include @@ -57,7 +58,9 @@ xen_msi_init(void) MPASS(num_io_irqs > 0); first_msi_irq = min(MINIMUM_MSI_INT, num_io_irqs); - num_io_irqs = first_msi_irq + NUM_MSI_INTS; + if (num_msi_irqs > UINT_MAX - first_msi_irq) + panic("num_msi_irq too high"); + num_io_irqs = first_msi_irq + num_msi_irqs; mtx_init(&msi_lock, "msi", NULL, MTX_DEF); } @@ -73,7 +76,7 @@ xen_msi_alloc(device_t dev, int count, int maxcount, i mtx_lock(&msi_lock); /* If we would exceed the max, give up. */ - if ((msi_last_irq + count) > NUM_MSI_INTS) { + if (msi_last_irq + count > num_msi_irqs) { mtx_unlock(&msi_lock); return (ENXIO); }