From nobody Thu Oct 06 16:20:24 2022 X-Original-To: dev-commits-src-main@mlmmj.nyi.freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2610:1c1:1:606c::19:1]) by mlmmj.nyi.freebsd.org (Postfix) with ESMTP id 4MjxVw3WvPz4dwWY; Thu, 6 Oct 2022 16:20:24 +0000 (UTC) (envelope-from git@FreeBSD.org) Received: from mxrelay.nyi.freebsd.org (mxrelay.nyi.freebsd.org [IPv6:2610:1c1:1:606c::19:3]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256 client-signature RSA-PSS (4096 bits) client-digest SHA256) (Client CN "mxrelay.nyi.freebsd.org", Issuer "R3" (verified OK)) by mx1.freebsd.org (Postfix) with ESMTPS id 4MjxVw2sDLz3TNd; Thu, 6 Oct 2022 16:20:24 +0000 (UTC) (envelope-from git@FreeBSD.org) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1665073224; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding; bh=R4pgrSvZQTnwqHQ9SnKkxfk6FfygWYVsRXhX/GVHO8k=; b=ePtTbaSg1cD/4QLlxV+S3bIhY95MvZ0BydUA3ScFFl7O6037sZyIHY2XbeFvioQn04yMlX z+ukvp7Tl8HyZX1AVPyV/cQpWOUYF9uPW1covH6mM1iflUkofU88sM9LWQkFwmSy0q1cLu JTSQ0ei3kdGj+nd+LSxMPZrvXArgg2A7UmI2EFkRtCmxFaG7N/28qgMdipO6giFy+M/EJd U2fDjOLJLrWbVm7MRAGoMWAXMfQYaCElSm/ZYF4h4Tsf1/YntTUfQx4b69YRawHbfpKFoa pfNzYBk8HuGyE8BwtT0uVGYdo8/cCLoq9Z9uab+r7lp6R/mxsNNCQ3YmJRrwwA== Received: from gitrepo.freebsd.org (gitrepo.freebsd.org [IPv6:2610:1c1:1:6068::e6a:5]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256) (Client did not present a certificate) by mxrelay.nyi.freebsd.org (Postfix) with ESMTPS id 4MjxVw1qH9zJPp; Thu, 6 Oct 2022 16:20:24 +0000 (UTC) (envelope-from git@FreeBSD.org) Received: from gitrepo.freebsd.org ([127.0.1.44]) by gitrepo.freebsd.org (8.16.1/8.16.1) with ESMTP id 296GKOEt027207; Thu, 6 Oct 2022 16:20:24 GMT (envelope-from git@gitrepo.freebsd.org) Received: (from git@localhost) by gitrepo.freebsd.org (8.16.1/8.16.1/Submit) id 296GKOZV027206; Thu, 6 Oct 2022 16:20:24 GMT (envelope-from git) Date: Thu, 6 Oct 2022 16:20:24 GMT Message-Id: <202210061620.296GKOZV027206@gitrepo.freebsd.org> To: src-committers@FreeBSD.org, dev-commits-src-all@FreeBSD.org, dev-commits-src-main@FreeBSD.org From: Alexander Motin Subject: git: c28220d8661e - main - vmd: Bypass MSI/MSI-X remapping when possible. List-Id: Commit messages for the main branch of the src repository List-Archive: https://lists.freebsd.org/archives/dev-commits-src-main List-Help: List-Post: List-Subscribe: List-Unsubscribe: Sender: owner-dev-commits-src-main@freebsd.org X-BeenThere: dev-commits-src-main@freebsd.org MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: 8bit X-Git-Committer: mav X-Git-Repository: src X-Git-Refname: refs/heads/main X-Git-Reftype: branch X-Git-Commit: c28220d8661ee1928bff7d2c6bcd3e64c25f927b Auto-Submitted: auto-generated ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1665073224; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding; bh=R4pgrSvZQTnwqHQ9SnKkxfk6FfygWYVsRXhX/GVHO8k=; b=prHoJPz6TW5aRb7QITcQ8RV9AxLqik7Yag5s9DfBeVWoUg83pUaNgqORYEhiTy40Ls1Fc2 iSPWsK2nXz26ieAAnk6wNLLnRdnMvWd1rlbLr1kr+uETkbIQO2aCYR7G1UR85KJZuAXo95 onPL0NNAEZDvFLVfmZ+iWlygyGROwdmqU8eXuw2F/SD02fROARvZJmhIhdw2+LJp3773CP xitROrlwFVg9X0SO2ZHH9A0TT/MJQQ+83eS+ydIEFrJswGHMTGeFWQ43c//HKqqTpi0p/s N6aco6Rg75GhlrqcwWcLt7NIxB8yDbuJPIJzf0Uy11aewbWcIbIcoQiCkcMEyA== ARC-Seal: i=1; s=dkim; d=freebsd.org; t=1665073224; a=rsa-sha256; cv=none; b=cxj4TvM1Ags6XURxbjDa3AkxpcunIaSJyE7x6bEtvz1cAJpmBPRDNcW4FjKuBU/W6N5pCd fwns874oX9/dqKe+T1nvJic9uZGpYs6knSNWbIGWAwPGHLbBn4ZC8EBBuKsEKOA4byDf/n rCZPRohUU6dnhY/VmFlblxb4sJAwyuQhiqX5O8pA8+fpN+I/shNhXngFdDKayPViPFayBv ZuGKQhgbZ3jh2PydtXywaMEjPBHAGGyuKM27Be4M6ZeluaPDU4pVdrsih1b/P0aQaHGTm2 wPeaQbGIWxQPrhu3muSty2j6ks+USiK2rP+0mj+0//WeKcUF84FxNmwfbNkigQ== ARC-Authentication-Results: i=1; mx1.freebsd.org; none X-ThisMailContainsUnwantedMimeParts: N The branch main has been updated by mav: URL: https://cgit.FreeBSD.org/src/commit/?id=c28220d8661ee1928bff7d2c6bcd3e64c25f927b commit c28220d8661ee1928bff7d2c6bcd3e64c25f927b Author: Alexander Motin AuthorDate: 2022-10-06 16:15:25 +0000 Commit: Alexander Motin CommitDate: 2022-10-06 16:15:25 +0000 vmd: Bypass MSI/MSI-X remapping when possible. By default all VMD devices remap children MSI/MSI-X interrupts into their own. It creates additional isolation, but also complicates things due to sharing, etc. Fortunately some VMD devices can bypass the remapping. Add tunable to control it for remap testing or if something go wrong. MFC after: 2 weeks --- share/man/man4/vmd.4 | 7 ++++++- sys/dev/vmd/vmd.c | 59 ++++++++++++++++++++++++++++++++++++++++++++++++++-- 2 files changed, 63 insertions(+), 3 deletions(-) diff --git a/share/man/man4/vmd.4 b/share/man/man4/vmd.4 index 74419fd87ffe..6c49e2b83ec0 100644 --- a/share/man/man4/vmd.4 +++ b/share/man/man4/vmd.4 @@ -27,7 +27,7 @@ .\" .\" $FreeBSD$ .\" -.Dd August 31, 2021 +.Dd October 6, 2022 .Dt VMD 4 .Os .Sh NAME @@ -57,6 +57,11 @@ The following tunables are settable via or .Xr sysctl 8 : .Bl -tag -width indent +.It Va hw.vmd.bypass_msi +By default all VMD devices remap children MSI/MSI-X interrupts into their +own. It creates additional isolation, but also complicates things due to +sharing, etc. Fortunately some VMD devices can bypass the remapping. +Defaults to 1. .It Va hw.vmd.max_msi Limits number of Message Signaled Interrupt (MSI) vectors allowed to each child device. diff --git a/sys/dev/vmd/vmd.c b/sys/dev/vmd/vmd.c index 208ea8a865f8..078101b58b2d 100644 --- a/sys/dev/vmd/vmd.c +++ b/sys/dev/vmd/vmd.c @@ -65,12 +65,14 @@ struct vmd_type { int flags; #define BUS_RESTRICT 1 #define VECTOR_OFFSET 2 +#define CAN_BYPASS_MSI 4 }; #define VMD_CAP 0x40 #define VMD_BUS_RESTRICT 0x1 #define VMD_CONFIG 0x44 +#define VMD_BYPASS_MSI 0x2 #define VMD_BUS_START(x) ((x >> 8) & 0x3) #define VMD_LOCK 0x70 @@ -78,6 +80,15 @@ struct vmd_type { SYSCTL_NODE(_hw, OID_AUTO, vmd, CTLFLAG_RD | CTLFLAG_MPSAFE, 0, "Intel Volume Management Device tuning parameters"); +/* + * By default all VMD devices remap children MSI/MSI-X interrupts into their + * own. It creates additional isolation, but also complicates things due to + * sharing, etc. Fortunately some VMD devices can bypass the remapping. + */ +static int vmd_bypass_msi = 1; +SYSCTL_INT(_hw_vmd, OID_AUTO, bypass_msi, CTLFLAG_RWTUN, &vmd_bypass_msi, 0, + "Bypass MSI remapping on capable hardware"); + /* * All MSIs within a group share address, so VMD can't distinguish them. * It makes no sense to use more than one per device, only if required by @@ -97,7 +108,7 @@ SYSCTL_INT(_hw_vmd, OID_AUTO, max_msix, CTLFLAG_RWTUN, &vmd_max_msix, 0, static struct vmd_type vmd_devs[] = { { 0x8086, 0x201d, "Intel Volume Management Device", 0 }, - { 0x8086, 0x28c0, "Intel Volume Management Device", BUS_RESTRICT }, + { 0x8086, 0x28c0, "Intel Volume Management Device", BUS_RESTRICT | CAN_BYPASS_MSI }, { 0x8086, 0x467f, "Intel Volume Management Device", BUS_RESTRICT | VECTOR_OFFSET }, { 0x8086, 0x4c3d, "Intel Volume Management Device", BUS_RESTRICT | VECTOR_OFFSET }, { 0x8086, 0x9a0b, "Intel Volume Management Device", BUS_RESTRICT | VECTOR_OFFSET }, @@ -216,6 +227,19 @@ vmd_write_config(device_t dev, u_int b, u_int s, u_int f, u_int reg, } } +static void +vmd_set_msi_bypass(device_t dev, bool enable) +{ + uint16_t val; + + val = pci_read_config(dev, VMD_CONFIG, 2); + if (enable) + val |= VMD_BYPASS_MSI; + else + val &= ~VMD_BYPASS_MSI; + pci_write_config(dev, VMD_CONFIG, val, 2); +} + static int vmd_intr(void *arg) { @@ -340,7 +364,10 @@ vmd_attach(device_t dev) LIST_INIT(&sc->vmd_users); sc->vmd_fist_vector = (t->flags & VECTOR_OFFSET) ? 1 : 0; sc->vmd_msix_count = pci_msix_count(dev); - if (pci_alloc_msix(dev, &sc->vmd_msix_count) == 0) { + if (vmd_bypass_msi && (t->flags & CAN_BYPASS_MSI)) { + sc->vmd_msix_count = 0; + vmd_set_msi_bypass(dev, true); + } else if (pci_alloc_msix(dev, &sc->vmd_msix_count) == 0) { sc->vmd_irq = malloc(sizeof(struct vmd_irq) * sc->vmd_msix_count, M_DEVBUF, M_WAITOK | M_ZERO); for (i = 0; i < sc->vmd_msix_count; i++) { @@ -362,6 +389,7 @@ vmd_attach(device_t dev) goto fail; } } + vmd_set_msi_bypass(dev, false); } sc->vmd_dma_tag = bus_get_dma_tag(dev); @@ -386,6 +414,8 @@ vmd_detach(device_t dev) error = device_delete_children(dev); if (error) return (error); + if (sc->vmd_msix_count == 0) + vmd_set_msi_bypass(dev, false); vmd_free(sc); return (0); } @@ -482,6 +512,11 @@ vmd_alloc_msi(device_t dev, device_t child, int count, int maxcount, struct vmd_irq_user *u; int i, ibest = 0, best = INT_MAX; + if (sc->vmd_msix_count == 0) { + return (PCIB_ALLOC_MSI(device_get_parent(device_get_parent(dev)), + child, count, maxcount, irqs)); + } + if (count > vmd_max_msi) return (ENOSPC); LIST_FOREACH(u, &sc->vmd_users, viu_link) { @@ -513,6 +548,11 @@ vmd_release_msi(device_t dev, device_t child, int count, int *irqs) struct vmd_softc *sc = device_get_softc(dev); struct vmd_irq_user *u; + if (sc->vmd_msix_count == 0) { + return (PCIB_RELEASE_MSI(device_get_parent(device_get_parent(dev)), + child, count, irqs)); + } + LIST_FOREACH(u, &sc->vmd_users, viu_link) { if (u->viu_child == child) { sc->vmd_irq[u->viu_vector].vi_nusers -= count; @@ -531,6 +571,11 @@ vmd_alloc_msix(device_t dev, device_t child, int *irq) struct vmd_irq_user *u; int i, ibest = 0, best = INT_MAX; + if (sc->vmd_msix_count == 0) { + return (PCIB_ALLOC_MSIX(device_get_parent(device_get_parent(dev)), + child, irq)); + } + i = 0; LIST_FOREACH(u, &sc->vmd_users, viu_link) { if (u->viu_child == child) @@ -562,6 +607,11 @@ vmd_release_msix(device_t dev, device_t child, int irq) struct vmd_softc *sc = device_get_softc(dev); struct vmd_irq_user *u; + if (sc->vmd_msix_count == 0) { + return (PCIB_RELEASE_MSIX(device_get_parent(device_get_parent(dev)), + child, irq)); + } + LIST_FOREACH(u, &sc->vmd_users, viu_link) { if (u->viu_child == child && sc->vmd_irq[u->viu_vector].vi_irq == irq) { @@ -580,6 +630,11 @@ vmd_map_msi(device_t dev, device_t child, int irq, uint64_t *addr, uint32_t *dat struct vmd_softc *sc = device_get_softc(dev); int i; + if (sc->vmd_msix_count == 0) { + return (PCIB_MAP_MSI(device_get_parent(device_get_parent(dev)), + child, irq, addr, data)); + } + for (i = sc->vmd_fist_vector; i < sc->vmd_msix_count; i++) { if (sc->vmd_irq[i].vi_irq == irq) break;