From nobody Fri Oct 20 21:54:36 2023 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 4SByzc6612z4yGqm; Fri, 20 Oct 2023 21:54:36 +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 4SByzc5ZZyz4fqf; Fri, 20 Oct 2023 21:54:36 +0000 (UTC) (envelope-from git@FreeBSD.org) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1697838876; 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=YGC5y9zfhwNi7MRhdo+ybKn5rgfu9XaeYX5A3VBSDo0=; b=Na3Hf36O6K8AwzlX/WI2yipt/OkYPHjGfaulZpnk2gUeLU1PHvDgcjkWCYoCKfc22znDTT T2ukgUCPovbvSFmmjV4Ouzsbh+FsbInpkm3QsCMbvrxaN32G2yXoPm08PPMR1CfMnZFD+1 OW2d/ChDfL45s+2kDJpQPdK64LjOmak+cpy1Ff/RvBSFe2iXaqsJRrn+5FUi/q8+o93+85 3s4wgMIZRFIEUfrM/UUZPd8YyoAquUYRNUEUH9LHB9QFOa5ZW9H+g4acc5QiQv9kJkSsUJ 3XkpdFYhGDJYN0DFT+gTpFg8IpX3VJRrFD3gNR90RHAVHJuIR6ZwFLk8vpdu/Q== ARC-Seal: i=1; s=dkim; d=freebsd.org; t=1697838876; a=rsa-sha256; cv=none; b=kPPhmTiQS+hwUzA1KaS0HNc0BYvxYAALK/4ccFUmRTi1M7hBNlL0lh1TpnKQRgPJMVrZVg rYLps67h5mS3ZbbWLGY3Y2tuOrrOf+VZ0KWKBY3X7ywoQZGQLkI6qtN3++UbwLFzaYKfiG ZHCcjbbZmXm3d58OL9V0xcdu4+lEROtPEOXKCxjNVmrH7xprnTpGJ2Q7uSfakTK1+YCX/T SUkvdh/6UkdgSEq6xVZ5n6ClSmvdaZ/OTZWoK6XzaReS4AhWX6v8/7PB/TnoHftcmxeixo 4QcfL30vA12fxvsEZtAUn3hY319Yt+qVLdHpzf+f57H4kdsjAzp6T80rsONKEw== ARC-Authentication-Results: i=1; mx1.freebsd.org; none ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1697838876; 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=YGC5y9zfhwNi7MRhdo+ybKn5rgfu9XaeYX5A3VBSDo0=; b=rSQsYZpP0PLiWFzl43Gc72BLPskvLlpLtIkKEdukZ+gJ/8iYRdhz+JvZzHFzk+1Vh6+Fky dCINOXp2vlLsHdWb4q2nMbx4FUvPpaM1SDb10EVvAMwNW96IemgAXesFVq7qLurmaY7jhN gCAc08SAjaj+HpUF8bS8aqr8ZowGUSML5faQnSpoenGNoeGwjyj5upPQ+wWcyGHPTenz8w 8MwU+rp/ZWUCEhUz7VSVsTHJLmIs8+/Fs70t+CsxEZUpsJX5G69dvM5cALHYZomuaHxfpk u144OTQ9elXETx862mCVBoN0XqS+UGXAjKkNY2Rhpe5OQjrUtmbWHPsKbC/Z2g== 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 4SByzc4LNHzpdV; Fri, 20 Oct 2023 21:54:36 +0000 (UTC) (envelope-from git@FreeBSD.org) Received: from gitrepo.freebsd.org ([127.0.1.44]) by gitrepo.freebsd.org (8.17.1/8.17.1) with ESMTP id 39KLsaJF022067; Fri, 20 Oct 2023 21:54:36 GMT (envelope-from git@gitrepo.freebsd.org) Received: (from git@localhost) by gitrepo.freebsd.org (8.17.1/8.17.1/Submit) id 39KLsaeA022064; Fri, 20 Oct 2023 21:54:36 GMT (envelope-from git) Date: Fri, 20 Oct 2023 21:54:36 GMT Message-Id: <202310202154.39KLsaeA022064@gitrepo.freebsd.org> To: src-committers@FreeBSD.org, dev-commits-src-all@FreeBSD.org, dev-commits-src-main@FreeBSD.org From: John Baldwin Subject: git: 2d4924892144 - main - x86 msi: Enable/disable IDT vectors for MSI groups all at once 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: jhb X-Git-Repository: src X-Git-Refname: refs/heads/main X-Git-Reftype: branch X-Git-Commit: 2d4924892144f653a7a7afba27ed1bf536dd7e51 Auto-Submitted: auto-generated The branch main has been updated by jhb: URL: https://cgit.FreeBSD.org/src/commit/?id=2d4924892144f653a7a7afba27ed1bf536dd7e51 commit 2d4924892144f653a7a7afba27ed1bf536dd7e51 Author: John Baldwin AuthorDate: 2023-10-20 21:52:38 +0000 Commit: John Baldwin CommitDate: 2023-10-20 21:52:38 +0000 x86 msi: Enable/disable IDT vectors for MSI groups all at once Unlike MSI-X, when a device uses multiple MSI interrupts, the entire group of interrupts are enabled/disabled at once in the relevant PCI config register. Currently, the interrupt code enables the IDT vector for each MSI interrupt when a handler is first registered. If the PCI device triggers an MSI interrupt which doesn't yet have a handler, this can trigger a panic when the Xrsvd ISR executes rather than treating it as a stray device interrupt. To fix, enable all the IDT vectors for an MSI group when the first interrupt handler is configured, and don't disable the IDT vectors until the last interrupt handler for the group is torn down. When migrating an MSI group between CPUs, enable/disable the entire group of IDT vectors if at least one interrupt handler is configured for the group. Reported by: jhay Reviewed by: kib Differential Revision: https://reviews.freebsd.org/D42232 --- sys/x86/x86/msi.c | 34 ++++++++++++++++++++-------------- 1 file changed, 20 insertions(+), 14 deletions(-) diff --git a/sys/x86/x86/msi.c b/sys/x86/x86/msi.c index 7f4d87c09453..246645efbc10 100644 --- a/sys/x86/x86/msi.c +++ b/sys/x86/x86/msi.c @@ -120,6 +120,7 @@ struct msi_intsrc { u_int msi_cpu; /* Local APIC ID. (g) */ u_int msi_count:8; /* Messages in this group. (g) */ u_int msi_maxcount:8; /* Alignment for this group. (g) */ + u_int msi_enabled:8; /* Enabled messages in this group. (g) */ u_int *msi_irqs; /* Group's IRQ list. (g) */ u_int msi_remap_cookie; }; @@ -204,7 +205,12 @@ msi_enable_intr(struct intsrc *isrc) { struct msi_intsrc *msi = (struct msi_intsrc *)isrc; - apic_enable_vector(msi->msi_cpu, msi->msi_vector); + msi = msi->msi_first; + if (msi->msi_enabled == 0) { + for (u_int i = 0; i < msi->msi_count; i++) + apic_enable_vector(msi->msi_cpu, msi->msi_vector + i); + } + msi->msi_enabled++; } static void @@ -212,7 +218,12 @@ msi_disable_intr(struct intsrc *isrc) { struct msi_intsrc *msi = (struct msi_intsrc *)isrc; - apic_disable_vector(msi->msi_cpu, msi->msi_vector); + msi = msi->msi_first; + msi->msi_enabled--; + if (msi->msi_enabled == 0) { + for (u_int i = 0; i < msi->msi_count; i++) + apic_disable_vector(msi->msi_cpu, msi->msi_vector + i); + } } static int @@ -277,11 +288,8 @@ msi_assign_cpu(struct intsrc *isrc, u_int apic_id) /* Must be set before BUS_REMAP_INTR as it may call back into MSI. */ msi->msi_cpu = apic_id; msi->msi_vector = vector; - if (msi->msi_intsrc.is_handlers > 0) - apic_enable_vector(msi->msi_cpu, msi->msi_vector); - for (i = 1; i < msi->msi_count; i++) { - sib = (struct msi_intsrc *)intr_lookup_source(msi->msi_irqs[i]); - if (sib->msi_intsrc.is_handlers > 0) + if (msi->msi_enabled > 0) { + for (i = 0; i < msi->msi_count; i++) apic_enable_vector(apic_id, vector + i); } error = BUS_REMAP_INTR(device_get_parent(msi->msi_dev), msi->msi_dev, @@ -317,15 +325,13 @@ msi_assign_cpu(struct intsrc *isrc, u_int apic_id) * to prevent races where we could miss an interrupt. If BUS_REMAP_INTR * failed then we disable and free the new, unused vector(s). */ - if (msi->msi_intsrc.is_handlers > 0) - apic_disable_vector(old_id, old_vector); - apic_free_vector(old_id, old_vector, msi->msi_irq); - for (i = 1; i < msi->msi_count; i++) { - sib = (struct msi_intsrc *)intr_lookup_source(msi->msi_irqs[i]); - if (sib->msi_intsrc.is_handlers > 0) + if (msi->msi_enabled > 0) { + for (i = 0; i < msi->msi_count; i++) apic_disable_vector(old_id, old_vector + i); - apic_free_vector(old_id, old_vector + i, msi->msi_irqs[i]); } + apic_free_vector(old_id, old_vector, msi->msi_irq); + for (i = 1; i < msi->msi_count; i++) + apic_free_vector(old_id, old_vector + i, msi->msi_irqs[i]); return (error); }