From nobody Fri Nov 13 22:07:58 2026 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 4jRBG65l8Dz6yCFB for ; Fri, 13 Nov 2026 22:07:58 +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) (No client certificate requested) by mx1.freebsd.org (Postfix) with ESMTPS id 4jRBG62Zb2z3KTj for ; Fri, 13 Nov 2026 22:07:58 +0000 (UTC) (envelope-from git@FreeBSD.org) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1794607678; 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=bgwYaHFDx5tHhp8B8WtmWnMn/jgUyGGUB7KRl4A4fOg=; b=o+WdC9Yt6AkM0rCrkiitqRoE2p/CsUxWu8vk5bgOuJyb0RHDaoekrpN40ZMaS7+JQedcaT k3wRFYnxzO2CC9/kiQRQI9tKSqA+WSoOaHf571hNhLgl1XhAJbaf/AzaOMRaVrFI1MeRBy qw2iyPNvOVYTTaJaGoktgNeZTGqYIhjlfUpRhEv7Gcs3BlwyoxOgsqey+l5kaUtqvjb7N4 bhE/z+EO9sTGCNwCbLNSVIm7KnVmfrwiwXszk/wcU3jXo2eKW6z/qYsvUzrlfPfvfdS5hf cWRj+bRT7M9XnkRnGbPb+FTNPkKdjePG8leDfkYWCdHP0FYWAaXFBbfYi7611g== ARC-Seal: i=1; a=rsa-sha256; d=freebsd.org; s=dkim; cv=none; t=1794607678; b=yGRGeVrEzmkIXVcI44OzY0lyQ6fCcG1T/oaW+7NNWqqvh4hx60i8fGoiUXmGmYysovJCBP TCfFo5d40dKT8YZJvxfjuNrYdo5J9Wwrnm9MruvodMUVb3KkCirBstAKHt16TqHAnM0S/x S+wIdN5xu4arBJu4EsL1mEfi82SXqBBZh0uTAmkXm/8llT4G2X0pYDTQbdQFCxxAJO9yTF Sd4lh90dE5GTjU+ioHBAxURswCz2domPNISLnbkrgDw4pa1krAMdT+Ugbx0nJXiLvfCxe6 VhHpHN1C9DEcrjpkxpref1eGtn4CzfzHk26W9WhUWt1K/BL/fFWll6cpJzLKYg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1794607678; 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=bgwYaHFDx5tHhp8B8WtmWnMn/jgUyGGUB7KRl4A4fOg=; b=cOEeeeHM89mFDAUq5mqqoJTitMDzcCgChOjuPZzJatxXKTaNft4ojgP1wp/mLuoThKYoUC MiMpCkSlGz9mY6Q+dIneV0SBn2EnTMQTffy6PCxNrS+7hXeqNnol6uN+H/NGbqnQJAQ71e 3kdMH1XSpESMgBRH9UOl1sbmbyOJgBnVseFYVWJjGkMoEMzY27oic5kH2aCFdPnp2hU9rn iisaBRMIwDGhmhG97NJwqUzNm+tCp+FkLqc5RSdYYET53+KDTR0MAGPQUzUWmP3EvMWchM PBrBmVl5EnKCDbs6mrCfncaHF5nFo7NescuvAcPL5oZ08FBhQCDUaejyPP6rGQ== ARC-Authentication-Results: i=1; mx1.freebsd.org; none Received: from gitrepo.freebsd.org (gitrepo.freebsd.org [IPv6:2610:1c1:1:6068::e6a:5]) by mxrelay.nyi.freebsd.org (Postfix) with ESMTP id 4jRBG61mpWzv3X for ; Fri, 13 Nov 2026 22:07:58 +0000 (UTC) (envelope-from git@FreeBSD.org) Received: from git (uid 1279) (envelope-from git@FreeBSD.org) id bef0 by gitrepo.freebsd.org (DragonFly Mail Agent v0.13+ on gitrepo.freebsd.org); Fri, 13 Nov 2026 22:07:58 +0000 To: src-committers@FreeBSD.org, dev-commits-src-all@FreeBSD.org, dev-commits-src-branches@FreeBSD.org From: Mark Johnston Subject: git: bc74694179cc - stable/14 - bhyve: Treat BAR registration failures as non-fatal List-Archive: https://lists.freebsd.org/archives/dev-commits-src-all X-BeenThere: dev-commits-src-all@freebsd.org List-Id: Commit messages for all branches of the src repository List-Post: List-Help: List-Subscribe: List-Unsubscribe: List-Owner: Precedence: list MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: 8bit X-Git-Committer: markj X-Git-Repository: src X-Git-Refname: refs/heads/stable/14 X-Git-Reftype: branch X-Git-Commit: bc74694179cc90ae33de39d945536bddc65ecb6b Auto-Submitted: auto-generated Date: Fri, 13 Nov 2026 22:07:58 +0000 Message-Id: <6af78a3e.bef0.23337cd1@gitrepo.freebsd.org> The branch stable/14 has been updated by markj: URL: https://cgit.FreeBSD.org/src/commit/?id=bc74694179cc90ae33de39d945536bddc65ecb6b commit bc74694179cc90ae33de39d945536bddc65ecb6b Author: Mark Johnston AuthorDate: 2026-10-20 15:41:21 +0000 Commit: Mark Johnston CommitDate: 2026-11-13 22:07:32 +0000 bhyve: Treat BAR registration failures as non-fatal Some guest operating systems (at least 9front) will leave device I/O space decoding enabled while probing BAR sizes. In this case, a sufficiently large 32-bit BAR can overlap with the HPET MMIO region fixed at 0xfed00000. This results in an assertion failure in modify_bar_registration(), even though the collision is transient, i.e., the guest will promptly map the BAR elsewhere. Tolerate such overlaps. Keep track of a BAR's registration state and make sure that modify_bar_registration() doesn't try to unregister an I/O space if registration failed. This fixes a problem where a 32MB framebuffer ends up overlapping with the HPET MMIO region, causing some guests to crash with an assertion failure when probing BARs during boot. PR: 290098 Reviewed by: bnovkov MFC after: 2 weeks Sponsored by: The FreeBSD Foundation Differential Revision: https://reviews.freebsd.org/D60748 (cherry picked from commit 6f051f0e56feba19731adfa6f6bd2a098b5091de) --- usr.sbin/bhyve/pci_emul.c | 46 +++++++++++++++++++++++++++++++--------------- usr.sbin/bhyve/pci_emul.h | 2 ++ 2 files changed, 33 insertions(+), 15 deletions(-) diff --git a/usr.sbin/bhyve/pci_emul.c b/usr.sbin/bhyve/pci_emul.c index 49e6b6136ff8..233323c355a8 100644 --- a/usr.sbin/bhyve/pci_emul.c +++ b/usr.sbin/bhyve/pci_emul.c @@ -626,12 +626,16 @@ static void modify_bar_registration(struct pci_devinst *pi, int idx, int registration) { struct pci_devemu *pe; + struct pcibar *bar; int error; - enum pcibar_type type; pe = pi->pi_d; - type = pi->pi_bar[idx].type; - switch (type) { + bar = &pi->pi_bar[idx]; + + if (!registration && !bar->registered) + return; + + switch (bar->type) { case PCIBAR_IO: { #ifdef __amd64__ @@ -639,30 +643,34 @@ modify_bar_registration(struct pci_devinst *pi, int idx, int registration) bzero(&iop, sizeof(struct inout_port)); iop.name = pi->pi_name; - iop.port = pi->pi_bar[idx].addr; - iop.size = pi->pi_bar[idx].size; + iop.port = bar->addr; + iop.size = bar->size; if (registration) { iop.flags = IOPORT_F_INOUT; iop.handler = pci_emul_io_handler; iop.arg = pi; error = register_inout(&iop); - } else + } else { error = unregister_inout(&iop); + assert(error == 0); + } #else struct mem_range mr; bzero(&mr, sizeof(struct mem_range)); mr.name = pi->pi_name; - mr.base = pi->pi_bar[idx].addr; - mr.size = pi->pi_bar[idx].size; + mr.base = bar->addr; + mr.size = bar->size; if (registration) { mr.flags = MEM_F_RW; mr.handler = pci_emul_iomem_handler; mr.arg1 = pi; mr.arg2 = idx; error = register_mem(&mr); - } else + } else { error = unregister_mem(&mr); + assert(error == 0); + } #endif break; } @@ -673,16 +681,18 @@ modify_bar_registration(struct pci_devinst *pi, int idx, int registration) bzero(&mr, sizeof(struct mem_range)); mr.name = pi->pi_name; - mr.base = pi->pi_bar[idx].addr; - mr.size = pi->pi_bar[idx].size; + mr.base = bar->addr; + mr.size = bar->size; if (registration) { mr.flags = MEM_F_RW; mr.handler = pci_emul_mem_handler; mr.arg1 = pi; mr.arg2 = idx; error = register_mem(&mr); - } else + } else { error = unregister_mem(&mr); + assert(error == 0); + } break; } case PCIBAR_ROM: @@ -692,10 +702,16 @@ modify_bar_registration(struct pci_devinst *pi, int idx, int registration) error = EINVAL; break; } - assert(error == 0); - if (pe->pe_baraddr != NULL) - (*pe->pe_baraddr)(pi, idx, registration, pi->pi_bar[idx].addr); + /* + * An error may legitimately occur if the guest is probing BARs and + * leaves decoding enabled. Keep track of this if it happens so that we + * can skip unregistration. + */ + bar->registered = (registration && error == 0); + + if (error == 0 && pe->pe_baraddr != NULL) + (*pe->pe_baraddr)(pi, idx, registration, bar->addr); } static void diff --git a/usr.sbin/bhyve/pci_emul.h b/usr.sbin/bhyve/pci_emul.h index c367169113f8..49ab733ebaf3 100644 --- a/usr.sbin/bhyve/pci_emul.h +++ b/usr.sbin/bhyve/pci_emul.h @@ -39,6 +39,7 @@ #include #include +#include #define PCI_BARMAX PCIR_MAX_BAR_0 /* BAR registers in a Type 0 header */ #define PCI_BARMAX_WITH_ROM (PCI_BARMAX + 1) @@ -97,6 +98,7 @@ struct pcibar { uint64_t size; uint64_t addr; uint8_t lobits; + bool registered; /* io region is registered */ }; #define PI_NAMESZ 40