From nobody Fri Aug 18 07:41:47 2023 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 4RRv2h2Bfdz4qrXp; Fri, 18 Aug 2023 07:41:48 +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 4RRv2h0gP8z3G2c; Fri, 18 Aug 2023 07:41:48 +0000 (UTC) (envelope-from git@FreeBSD.org) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1692344508; 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=DXcT1ky1AAwKgPOSoDpEQKq31hGqMA7uiP8jebZb8Yw=; b=qM/Qt9KMCDc7r/mX6DbN+j8WdFO8b9qVt7rsAlTWC/fdxS5JSK9mpafZKEiQnngWnQBQhI 4QRl2+sTk7LtT3m/MFczTn9QTVHGZ+Y64IfRKE8lQRtwd68tvKsJpFyUo+RFgaRnHTp6yV PwApienxv4EA/j9dVECt6gQTN0aof6ZazaSbBUa9HX4/8xgh2kCR5DMUIkVPic8z57g/UB /olYrDTcOBJDFCakj69NVfplPZ5KYngj1lTzlYPZV+nlnsrGwikKZF2TyNzbz66ZtrkoCE TnLrF3H/fkLQlgZsuLLgrOueBAMjIFyK9UQKSZ9kG8PB0ZpezSPv4S7F+gKJoQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1692344508; 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=DXcT1ky1AAwKgPOSoDpEQKq31hGqMA7uiP8jebZb8Yw=; b=HkOWWDFlr9qW4FK5X7+dlsLohDUS0w5jSICY5gCn7CseavVINXJu5hRz1ymWL4MSEu/cwS 7G2BFgsJYuVZBTgiqkyglxNcmNd5gwTj2n+952u/oyja9YSvWZ/IdqJw5EgGHT4y7Wiq5B FomJwT7Y/oS8fc8qktQ4Fjlv0PfBuux5DYgT+yIZutQIZ8OIOP9z4xRBColHJh1C8GRzsj beFofZCGAyJve/CPYjMKx0KbYeIYMGyhWxVzxLE8hunQGcWIJQ2N7vzZXQMIYy7S1yEZdr dRAd278iSQPxev4CHMzbRz7sR/jB55lgmZOXS7GqJWmFXRLTOutP5nK/yXSsMQ== ARC-Seal: i=1; s=dkim; d=freebsd.org; t=1692344508; a=rsa-sha256; cv=none; b=C0phaawJDG4Br7oEkseeu/6n4qUEWO10Xrtm0tySUApMIkhhgBVx3khrcJU1bcV3gN7cu9 u4HSGD3WrtbD2PkWJQgAfHkZr4rAIB/RxtU14Q1wWI6VBjjSFuRSflng4Ip+T0AaygVKvh 6cJTMO4oLeivuvFAOK+ELjwdTRKpsJ8P/1nMzuw6FClk+sbWoUCsnOa2ZcMqhDADHT7Z3b 2uvMWV+FwafrMbEkuBGLLhCc/ccEwYAmG1i6g8f4R139nMfyjvcVIfNeIbtun3LuFMoOvG e0YrFWqCPVknbmGdgs0GZl0kVcZKBG6l72rtsMI2Q+4quPVwdmXTT/Qzg2mfng== ARC-Authentication-Results: i=1; mx1.freebsd.org; none 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 4RRv2g6rfcz174m; Fri, 18 Aug 2023 07:41:47 +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 37I7flgd066506; Fri, 18 Aug 2023 07:41:47 GMT (envelope-from git@gitrepo.freebsd.org) Received: (from git@localhost) by gitrepo.freebsd.org (8.17.1/8.17.1/Submit) id 37I7flI6066501; Fri, 18 Aug 2023 07:41:47 GMT (envelope-from git) Date: Fri, 18 Aug 2023 07:41:47 GMT Message-Id: <202308180741.37I7flI6066501@gitrepo.freebsd.org> To: src-committers@FreeBSD.org, dev-commits-src-all@FreeBSD.org, dev-commits-src-branches@FreeBSD.org From: Corvin =?utf-8?Q?K=C3=B6hne?= Subject: git: 13a371bcdfdd - stable/13 - bhyve: read out graphics stolen memory address and size 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: corvink X-Git-Repository: src X-Git-Refname: refs/heads/stable/13 X-Git-Reftype: branch X-Git-Commit: 13a371bcdfdde22344f01fbbb04e713c27424c32 Auto-Submitted: auto-generated The branch stable/13 has been updated by corvink: URL: https://cgit.FreeBSD.org/src/commit/?id=13a371bcdfdde22344f01fbbb04e713c27424c32 commit 13a371bcdfdde22344f01fbbb04e713c27424c32 Author: Corvin Köhne AuthorDate: 2023-05-11 08:53:15 +0000 Commit: Corvin Köhne CommitDate: 2023-08-18 07:32:07 +0000 bhyve: read out graphics stolen memory address and size This is the first step to emulate the graphics stolen memory register. Note that the graphics stolen memory is somehow confusing. On the one hand the Intel Open Source HD Graphics Programmers' Reference Manual states that it's only GPU accessible. As the CPU can't access the area, the guest shouldn't need it. On the other hand, the Intel GOP driver refuses to work properly, if it's not set to a proper address. Intel itself maps it into the guest by EPT [1]. At the moment, we're not aware of any situation where this EPT mapping is required, so we don't do it yet. Intel also states that the Windows driver for Tiger Lake reads the address of the graphics stolen memory [2]. As the GVT-d code doesn't support Tiger Lake in its first implementation, we can't check how it behaves. We should keep an eye on it. [1] https://github.com/projectacrn/acrn-hypervisor/blob/e28d6fbfdfd556ff1bc3ff330e41d4ddbaa0f897/devicemodel/hw/pci/passthrough.c#L655-L657 [2] https://github.com/projectacrn/acrn-hypervisor/blob/e28d6fbfdfd556ff1bc3ff330e41d4ddbaa0f897/devicemodel/hw/pci/passthrough.c#L626-L629 Reviewed by: markj MFC after: 1 week Sponsored by: Beckhoff Automation GmbH & Co. KG Differential Revision: https://reviews.freebsd.org/D40039 (cherry picked from commit 4a9bf50f408eb9f1acc220dba2b260ec610fd15b) --- usr.sbin/bhyve/pci_gvt-d.c | 73 +++++++++++++++++++++++++++++++++++++++++++++- 1 file changed, 72 insertions(+), 1 deletion(-) diff --git a/usr.sbin/bhyve/pci_gvt-d.c b/usr.sbin/bhyve/pci_gvt-d.c index 767b8ee3127f..0be740921c92 100644 --- a/usr.sbin/bhyve/pci_gvt-d.c +++ b/usr.sbin/bhyve/pci_gvt-d.c @@ -6,6 +6,9 @@ */ #include +#include + +#include #include @@ -16,6 +19,8 @@ #define PCI_VENDOR_INTEL 0x8086 +#define GVT_D_MAP_GSM 0 + static int gvt_d_probe(struct pci_devinst *const pi) { @@ -36,12 +41,78 @@ gvt_d_probe(struct pci_devinst *const pi) return (0); } +/* + * Note that the graphics stolen memory is somehow confusing. On the one hand + * the Intel Open Source HD Graphics Programmers' Reference Manual states that + * it's only GPU accessible. As the CPU can't access the area, the guest + * shouldn't need it. On the other hand, the Intel GOP driver refuses to work + * properly, if it's not set to a proper address. + * + * Intel itself maps it into the guest by EPT [1]. At the moment, we're not + * aware of any situation where this EPT mapping is required, so we don't do it + * yet. + * + * Intel also states that the Windows driver for Tiger Lake reads the address of + * the graphics stolen memory [2]. As the GVT-d code doesn't support Tiger Lake + * in its first implementation, we can't check how it behaves. We should keep an + * eye on it. + * + * [1] + * https://github.com/projectacrn/acrn-hypervisor/blob/e28d6fbfdfd556ff1bc3ff330e41d4ddbaa0f897/devicemodel/hw/pci/passthrough.c#L655-L657 + * [2] + * https://github.com/projectacrn/acrn-hypervisor/blob/e28d6fbfdfd556ff1bc3ff330e41d4ddbaa0f897/devicemodel/hw/pci/passthrough.c#L626-L629 + */ static int -gvt_d_init(struct pci_devinst *const pi __unused, nvlist_t *const nvl __unused) +gvt_d_setup_gsm(struct pci_devinst *const pi) { + struct passthru_softc *sc; + struct passthru_mmio_mapping *gsm; + size_t sysctl_len; + int error; + + sc = pi->pi_arg; + + gsm = passthru_get_mmio(sc, GVT_D_MAP_GSM); + if (gsm == NULL) { + warnx("%s: Unable to access gsm", __func__); + return (-1); + } + + sysctl_len = sizeof(gsm->hpa); + error = sysctlbyname("hw.intel_graphics_stolen_base", &gsm->hpa, + &sysctl_len, NULL, 0); + if (error) { + warn("%s: Unable to get graphics stolen memory base", + __func__); + return (-1); + } + sysctl_len = sizeof(gsm->len); + error = sysctlbyname("hw.intel_graphics_stolen_size", &gsm->len, + &sysctl_len, NULL, 0); + if (error) { + warn("%s: Unable to get graphics stolen memory length", + __func__); + return (-1); + } + gsm->hva = NULL; /* unused */ + return (0); } +static int +gvt_d_init(struct pci_devinst *const pi, nvlist_t *const nvl __unused) +{ + int error; + + if ((error = gvt_d_setup_gsm(pi)) != 0) { + warnx("%s: Unable to setup Graphics Stolen Memory", __func__); + goto done; + } + +done: + return (error); +} + static void gvt_d_deinit(struct pci_devinst *const pi __unused) {