From nobody Thu Oct 20 14:23:45 2022 X-Original-To: dev-commits-src-all@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 4MtVFt1ByQz4fS71; Thu, 20 Oct 2022 14:23:46 +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 4MtVFt0fdqz3wZS; Thu, 20 Oct 2022 14:23:46 +0000 (UTC) (envelope-from git@FreeBSD.org) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1666275826; 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=K0RPwx8lsmE2irM4x3A407KLH1HIp456DbEP3kHpdwA=; b=iNsP5myJgIIupMk60cz5WGKKyTLNj5AjVb4diDvGoqq5GHZJHMy38Ge/emmsXO/gTz3TrQ vspWBtUhMWskn475ekzN9xxnbv5tobQn6zqNR7mdDGEwBedmtTnQdacarJl07Ot5vsc9/u mi2MCYoUCRt1SZtp3+Rpu9KN6JMNoiNu3CPvFw2cofVKOmle5vJHmhc2tK4iWEyTDhOYpr zw5P4VWLZlHMxuOFqa10nQDj9XcE4UdM/ePnlyc5rwJCpvC0nU237OK2XdPC6AlymWEmrL fBx8pGEK0ERi92DGFc7P/AJv7etQOeVEvhiWjEFjpefbVcHI2/qUex1KWOZIOA== 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 4MtVFs6nltztp6; Thu, 20 Oct 2022 14:23:45 +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 29KENjlw039761; Thu, 20 Oct 2022 14:23:45 GMT (envelope-from git@gitrepo.freebsd.org) Received: (from git@localhost) by gitrepo.freebsd.org (8.16.1/8.16.1/Submit) id 29KENjCh039760; Thu, 20 Oct 2022 14:23:45 GMT (envelope-from git) Date: Thu, 20 Oct 2022 14:23:45 GMT Message-Id: <202210201423.29KENjCh039760@gitrepo.freebsd.org> To: src-committers@FreeBSD.org, dev-commits-src-all@FreeBSD.org, dev-commits-src-branches@FreeBSD.org From: Alexander Motin Subject: git: 5e98842589e1 - stable/13 - vmd: Bypass MSI/MSI-X remapping when possible. List-Id: Commit messages for all branches of the src repository List-Archive: https://lists.freebsd.org/archives/dev-commits-src-all List-Help: List-Post: List-Subscribe: List-Unsubscribe: Sender: owner-dev-commits-src-all@freebsd.org X-BeenThere: dev-commits-src-all@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/stable/13 X-Git-Reftype: branch X-Git-Commit: 5e98842589e17308b9b7f3eacf25a99a6ecddc38 Auto-Submitted: auto-generated ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1666275826; 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=K0RPwx8lsmE2irM4x3A407KLH1HIp456DbEP3kHpdwA=; b=TOLCb8OPviRf90zzvF7feuADs39GH4TlGH2vlsOQxht0WhWidip1+hwGWIij7eGehHuF5C lWCoU7KPWHneQ/foXcPu6MjFtiiLJRB6QUxQlMnOL2Ufy45lrr8LCezEEWOjgyGmfr+jaD yF3VZc+WrsCUmh05d0CqX+/sWQ1oBV26bCoHI6tmxiGa/73bvY3qjyF3S3zeQ/LFj91GYJ 9sK0u9afCyZAsgfXlNuGPQVCxP+wU5xy9aFycDlSR1LtU6nKfdfi77Jvl1WHfUxAAaWdCw wpJHi1/Vj5iG1lGGRz6b+f6Ms0xN5VgmwcYoPEqyr2DHB9f/Bs5qwyVYvcTecg== ARC-Seal: i=1; s=dkim; d=freebsd.org; t=1666275826; a=rsa-sha256; cv=none; b=iZsmSZLa78y91DfW/UaKt+6LVMSPbCZ9D9RefJkVUusA9ujSHQE9alGwcdZJfzAQWUI39T eiT08qF2/u/U4yCsepwYcw4fecABY5gfw/m/D5iWKVSxIkupjeJArj7qrHLWaAIBmln5Xl c94oB6Rh0LSKqDaefVB/6lo/EATzD9aLeCqfWTX7HUNQWiRxWowqOIDRXAbw0YIyzawzjE 7RF0aVCz7yCrpH0/xcfYGvlXVKRKr14UPwunNEEkl1jRnDtT0PAD+SzgFCiezDVQNjcIrK vGbO+h7C5Ylm827z9Onl0xjpl1D3WjHVkGw7Zf5FZSZ+q0oYrdguoC0FLQO/Ww== ARC-Authentication-Results: i=1; mx1.freebsd.org; none X-ThisMailContainsUnwantedMimeParts: N The branch stable/13 has been updated by mav: URL: https://cgit.FreeBSD.org/src/commit/?id=5e98842589e17308b9b7f3eacf25a99a6ecddc38 commit 5e98842589e17308b9b7f3eacf25a99a6ecddc38 Author: Alexander Motin AuthorDate: 2022-10-06 16:15:25 +0000 Commit: Alexander Motin CommitDate: 2022-10-20 14:22:23 +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 (cherry picked from commit c28220d8661ee1928bff7d2c6bcd3e64c25f927b) --- 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 08fac27d3037..3ee65c97d017 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;