From nobody Tue Aug 5 14:03:18 2025 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 4bxFWW3LHBz63GtT; Tue, 05 Aug 2025 14:03:19 +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 "R10" (verified OK)) by mx1.freebsd.org (Postfix) with ESMTPS id 4bxFWW0qqtz3FNW; Tue, 05 Aug 2025 14:03:19 +0000 (UTC) (envelope-from git@FreeBSD.org) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1754402599; 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=sRNM5V2wgvnaqf2l0gSJHtgQeKOmtgNP6GQbPY361WE=; b=hGms2Ez9rLrPapxGnmMXzEAailFJ8UyQ2dm/xrD3CozWJMR0vsVQVBcCvCEvhrgPkAV92v vKlfvw7DQ03WYkya4K7bPM8UlL+C860AwbB9lu6O4h7tAQM1TYt5SvbNiYCsXsnsZFw3P3 keGWsJ+qMTCvQMzi0Dj+/QUDcmEn6qtRfh4Il81DDgrgldXvqDn+/deMQKyADQSRzeStvx Qvf/sC4ENwvUIZMTLatGHt9io/mNW618rvYoVbY1KBJkgn9dHtJ4q1p1VhPK5NLz3BhvVh pJaB2mPMjlUs8Z/BZjcy16Dw6i0U+JSmNYzqgE3WAhaB//tp9VBOT2VHUR1K4g== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1754402599; 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=sRNM5V2wgvnaqf2l0gSJHtgQeKOmtgNP6GQbPY361WE=; b=opLLj0eJ4x4fjEEqKjTr78sG5+tc1NqOEnDOVHXd0+QJ7FLWrHxKEKZ43l/GFPU1MCXLEj YDrnd4HdRDgS09HEJigv9n29e9Oemdf00P14hwc1IkQrpGMPJqhkQFZTLx+fu2GB5cqhob hGcFeUugpfLAckUDhWLnM5u8brZ3p8+HaBvooSR38Aj+Ld4JY8LZI43lDEmz464yH5+mvZ IWnLeu8PoYP53LXHwgKJo4ManVijkqqraN6y0Qjm+Ms1X3lrLWraOrVjnF81znczaRotJ/ v0PxNn/4bWQvnt+nsRC090MOwA0RH2sPwsYbwBK9HyPLVApQhHPiblC3lzr5PQ== ARC-Authentication-Results: i=1; mx1.freebsd.org; none ARC-Seal: i=1; s=dkim; d=freebsd.org; t=1754402599; a=rsa-sha256; cv=none; b=ENPnH1QgtIv/ka/G87VyeGuZxfbiTzDST0RjaoX2xOdQdIFXvkJaVCnzvnNQzjaV2GhHLp 6rEj9ifoUDnKUNX6tSMm1JL+vfGYLPruEXSYy+m1V6gfYYJPPAl21CBQHb54YQwEH3h6tR CRzO77p3Zyp95S5+G+tU9cAbaSbaeA1O0GuwgrszEB84I5eO0UBSuqy9GnRz7gtBhokHAh CFEzvX4haNmm1fWd1rkfEPdH0+N+D9eLGSLOtp8cNmq9GqIz6h0sef+oQJaXB8OeKq6yuA MnJE2dSxbaZstM2OI5PSozYeUQN4wyjotrBnY0sNAUYsOt3jMnU0thfS2HZPaw== 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 4bxFWW0GM0zdgk; Tue, 05 Aug 2025 14:03:19 +0000 (UTC) (envelope-from git@FreeBSD.org) Received: from gitrepo.freebsd.org ([127.0.1.44]) by gitrepo.freebsd.org (8.18.1/8.18.1) with ESMTP id 575E3I3e070672; Tue, 5 Aug 2025 14:03:18 GMT (envelope-from git@gitrepo.freebsd.org) Received: (from git@localhost) by gitrepo.freebsd.org (8.18.1/8.18.1/Submit) id 575E3IP8070669; Tue, 5 Aug 2025 14:03:18 GMT (envelope-from git) Date: Tue, 5 Aug 2025 14:03:18 GMT Message-Id: <202508051403.575E3IP8070669@gitrepo.freebsd.org> To: src-committers@FreeBSD.org, dev-commits-src-all@FreeBSD.org, dev-commits-src-main@FreeBSD.org From: Corvin =?utf-8?Q?K=C3=B6hne?= Subject: git: 6dda2653bd0e - main - bhyve: add interface to protect BAR regions of passthru devices 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: X-BeenThere: dev-commits-src-main@freebsd.org Sender: owner-dev-commits-src-main@FreeBSD.org MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: 8bit X-Git-Committer: corvink X-Git-Repository: src X-Git-Refname: refs/heads/main X-Git-Reftype: branch X-Git-Commit: 6dda2653bd0ee297b114682972b11d6d3c74a6a6 Auto-Submitted: auto-generated The branch main has been updated by corvink: URL: https://cgit.FreeBSD.org/src/commit/?id=6dda2653bd0ee297b114682972b11d6d3c74a6a6 commit 6dda2653bd0ee297b114682972b11d6d3c74a6a6 Author: Corvin Köhne AuthorDate: 2024-01-08 14:04:04 +0000 Commit: Corvin Köhne CommitDate: 2025-08-05 14:02:09 +0000 bhyve: add interface to protect BAR regions of passthru devices We need an interface for protecting BAR regions to make it easier to use this feature and to make it usable by external emulations like the GVT-d emulation. Reviewed by: jhb MFC after: 1 week Sponsored by: Beckhoff Automation GmbH & Co. KG Differential Revision: https://reviews.freebsd.org/D45341 --- usr.sbin/bhyve/pci_passthru.c | 39 +++++++++++++++++++++++++++++++++++++++ usr.sbin/bhyve/pci_passthru.h | 3 +++ 2 files changed, 42 insertions(+) diff --git a/usr.sbin/bhyve/pci_passthru.c b/usr.sbin/bhyve/pci_passthru.c index 2b84c561927a..8ddcd8bd56e8 100644 --- a/usr.sbin/bhyve/pci_passthru.c +++ b/usr.sbin/bhyve/pci_passthru.c @@ -752,6 +752,45 @@ set_pcir_handler(struct passthru_softc *sc, int reg, int len, return (0); } +int +passthru_set_bar_handler(struct passthru_softc *sc, int baridx, uint64_t off, + uint64_t size, passthru_read_handler rhandler, + passthru_write_handler whandler) +{ + struct passthru_bar_handler *handler_new; + struct passthru_bar_handler *handler; + + assert(sc->psc_bar[baridx].type == PCIBAR_IO || + sc->psc_bar[baridx].type == PCIBAR_MEM32 || + sc->psc_bar[baridx].type == PCIBAR_MEM64); + assert(sc->psc_bar[baridx].size >= off + size); + assert(off < off + size); + + handler_new = malloc(sizeof(struct passthru_bar_handler)); + if (handler_new == NULL) { + return (ENOMEM); + } + + handler_new->off = off; + handler_new->size = size; + handler_new->read = rhandler; + handler_new->write = whandler; + + TAILQ_FOREACH(handler, &sc->psc_bar_handler[baridx], chain) { + if (handler->off < handler_new->off) { + assert(handler->off + handler->size < handler_new->off); + continue; + } + assert(handler->off > handler_new->off + handler_new->size); + TAILQ_INSERT_BEFORE(handler, handler_new, chain); + return (0); + } + + TAILQ_INSERT_TAIL(&sc->psc_bar_handler[baridx], handler_new, chain); + + return (0); +} + static int passthru_legacy_config(nvlist_t *nvl, const char *opts) { diff --git a/usr.sbin/bhyve/pci_passthru.h b/usr.sbin/bhyve/pci_passthru.h index fc3fdbc1719f..9e7b27d95735 100644 --- a/usr.sbin/bhyve/pci_passthru.h +++ b/usr.sbin/bhyve/pci_passthru.h @@ -53,3 +53,6 @@ struct passthru_mmio_mapping *passthru_get_mmio(struct passthru_softc *sc, struct pcisel *passthru_get_sel(struct passthru_softc *sc); int set_pcir_handler(struct passthru_softc *sc, int reg, int len, cfgread_handler rhandler, cfgwrite_handler whandler); +int passthru_set_bar_handler(struct passthru_softc *sc, int baridx, + uint64_t off, uint64_t size, passthru_read_handler rhandler, + passthru_write_handler whandler);