From nobody Thu May 15 14:01:49 2025 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 4ZysMd5L1qz5wNxY; Thu, 15 May 2025 14:01:49 +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 "R11" (verified OK)) by mx1.freebsd.org (Postfix) with ESMTPS id 4ZysMd2mqgz3QKL; Thu, 15 May 2025 14:01:49 +0000 (UTC) (envelope-from git@FreeBSD.org) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1747317709; 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=+q9YFuBdr5fRgI6JsoKIkeZcdixnyMu0/xlG++dM9DM=; b=M1wPSyiRP7r3fJgDUCSi6lAKczFxmHRlqHomwtyvt1pAbiYTC0tPvVHlbOhJU2foxa5UEL gyD8Yo4RAWOaywBKceaFYIPyc1EAefiiPxT93ALeZ8m8Sp/pF7YI9ctna0sFGd0hLD1S+L +rY+B2HfEQ491FjtPa32nDS6s/AIA0Z3BBIzAAdsgEcxy80q7/yDDc6D3Ue72IAVEHVb6t gyg1eM1lf7v7YcL3O8nBOI8V3b0MDT53ETcbR924xnhVlL7i5ELdzdoXDIBpnT1xz2uKic aNmPHBxXqFbWoy/gJxUmeyezXsv101nSGC86LVFG9PD553nqgEKyU8KBslEnzQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1747317709; 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=+q9YFuBdr5fRgI6JsoKIkeZcdixnyMu0/xlG++dM9DM=; b=LH8ICdeo0n6qmzWX5wZ29w0b+itiLw9CTKJ+FvHfch0+e3SnAnyDfVCNqguV50YnDvkzla j+eFOKujnFEZEil3dR2E7bPg905kMw2VtET4LnHUvhY3cgdNGquwqVH56upj5HLVqQ5Z5/ 1NkzteNr1Z1aGxk4nxWqf4PZKd55OB4uP0Ih96KjlTQlQQSOOcMjxLG4tc39VlVvtjx3IP vHoPvvjBtWon3C7xjZUmenCaO7plNCo/LbWhT0Tec5Yhhq14QaRmWz6D9pEWOMytghe/aQ rehMHPXsaMiy+LQdXfywI0mp2WYCPy3oHEWkWC6X4aFsqAX4Q9Z/ZXRCXmziaQ== ARC-Seal: i=1; s=dkim; d=freebsd.org; t=1747317709; a=rsa-sha256; cv=none; b=pUwNbXHAXJ0k4jUgnPdnjftq893GKku81nBAjnGp6aNk5BkbhzUM1Ry3SmpO+O1k2KXZZF iaPmgwv7E8K7/zEM4dz4rj/C6NS7bfmc1T1Ku0Wn9PCeVm7ac0kNnvnkzC5+q/5NdKAAf2 zWizQ8X86ttVXYHhgH7yfKCPeDBMScrGKHrI3qqi0lZkNcCgMH/173hTdOESrwBDKst/DC mTdrz3ZCZVb8aNNmrpWzyAHykOtUtUkst8rtQ18CjJVg5vPmYqV0Z3I7LOi3tHE6/aes3j 6Yi/w4sRp3DXly5NkgU25orJJqhNAVlo4kaieorwWzvMBa8JPA9k4TRoPS+sJw== 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 4ZysMd2GDgz4nf; Thu, 15 May 2025 14:01:49 +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 54FE1n6g018573; Thu, 15 May 2025 14:01:49 GMT (envelope-from git@gitrepo.freebsd.org) Received: (from git@localhost) by gitrepo.freebsd.org (8.18.1/8.18.1/Submit) id 54FE1nTk018570; Thu, 15 May 2025 14:01:49 GMT (envelope-from git) Date: Thu, 15 May 2025 14:01:49 GMT Message-Id: <202505151401.54FE1nTk018570@gitrepo.freebsd.org> To: src-committers@FreeBSD.org, dev-commits-src-all@FreeBSD.org, dev-commits-src-main@FreeBSD.org From: Konstantin Belousov Subject: git: d8c4c2ce68ee - main - bhyve x86: when accessing non-backed gpa, emulate hw 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: X-BeenThere: dev-commits-src-all@freebsd.org Sender: owner-dev-commits-src-all@FreeBSD.org MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: 8bit X-Git-Committer: kib X-Git-Repository: src X-Git-Refname: refs/heads/main X-Git-Reftype: branch X-Git-Commit: d8c4c2ce68eec8bac4e5cd0d133b8342e7a7f05d Auto-Submitted: auto-generated The branch main has been updated by kib: URL: https://cgit.FreeBSD.org/src/commit/?id=d8c4c2ce68eec8bac4e5cd0d133b8342e7a7f05d commit d8c4c2ce68eec8bac4e5cd0d133b8342e7a7f05d Author: Konstantin Belousov AuthorDate: 2025-05-04 17:01:20 +0000 Commit: Konstantin Belousov CommitDate: 2025-05-15 14:01:40 +0000 bhyve x86: when accessing non-backed gpa, emulate hw which reads all bits one, and ignores writes. PR: 286467 Reviewed by: markj (previous version) Sponsored by: The FreeBSD Foundation MFC after: 1 week Differential revision: https://reviews.freebsd.org/D50116 --- usr.sbin/bhyve/amd64/Makefile.inc | 2 +- usr.sbin/bhyve/amd64/mem_x86.c | 82 +++++++++++++++++++++++++++++++++++++++ 2 files changed, 83 insertions(+), 1 deletion(-) diff --git a/usr.sbin/bhyve/amd64/Makefile.inc b/usr.sbin/bhyve/amd64/Makefile.inc index 0a9b13901978..92e53433ff01 100644 --- a/usr.sbin/bhyve/amd64/Makefile.inc +++ b/usr.sbin/bhyve/amd64/Makefile.inc @@ -7,7 +7,7 @@ SRCS+= \ inout.c \ ioapic.c \ kernemu_dev.c \ - mem_md.c \ + mem_x86.c \ mptbl.c \ pci_fbuf.c \ pci_gvt-d.c \ diff --git a/usr.sbin/bhyve/amd64/mem_x86.c b/usr.sbin/bhyve/amd64/mem_x86.c new file mode 100644 index 000000000000..742d827db47f --- /dev/null +++ b/usr.sbin/bhyve/amd64/mem_x86.c @@ -0,0 +1,82 @@ +/*- + * SPDX-License-Identifier: BSD-2-Clause + * + * Copyright (c) 2025 The FreeBSD Foundation + * + * This software was developed by Konstantin Belousov + * under sponsorship from the FreeBSD Foundation. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND + * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE + * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL + * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS + * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) + * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY + * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF + * SUCH DAMAGE. + */ + +#include +#include +#include +#include + +#include + +#include "debug.h" +#include "mem.h" + +static int +no_mem_handler(struct vcpu *vcpu __unused, int dir, uint64_t addr __unused, + int size, uint64_t *val, void *arg1 __unused, long arg2 __unused) +{ + if (dir == MEM_F_READ) { + switch (size) { + case 1: + *val = 0xff; + break; + case 2: + *val = 0xffff; + break; + case 4: + *val = 0xffffffff; + break; + case 8: + *val = 0xffffffffffffffff; + break; + } + } + return (0); +} + +static struct mem_range fb_entry = { + .handler = no_mem_handler, + .base = 0, + .size = 0xffffffffffffffff, +}; + +/* + * x86 hardware ignores writes without receiver, and returns all 1's + * from reads without response to transaction. + */ +int +mmio_handle_non_backed_mem(struct vcpu *vcpu __unused, uint64_t paddr, + struct mem_range **mr_paramp) +{ + *mr_paramp = &fb_entry; + EPRINTLN("Emulating access to non-existent address to %#lx\n", + paddr); + return (0); +}