From nobody Sun Mar 27 20:13:53 2022 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 7EB651A52D3E; Sun, 27 Mar 2022 20:13:53 +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 4KRRqP2hmsz4nk9; Sun, 27 Mar 2022 20:13:53 +0000 (UTC) (envelope-from git@FreeBSD.org) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1648412033; 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=dFu8t5dvOQUhGUezeYP0ozI0il+OFjfuxWGR5OoeHJI=; b=CEr/uAm68ooi9ijI+BsCWeODO2qY4O0GTxHAgnYVZ2Ab9XlbgZgZEbscerS+e55YCQlM2l Qf9berAr8gwqWovBkOpj4DksbVHtPb2J77/9jFe9t3Dyt1TLLl02xVRD1+Mj9vWDy3C+eE ZhajHuRnyDLgamGvMSrpGPdIfNVerUtSnGMe5TfNMcxsdWQnPKA16PHdD5W5mYCvkYevUS /KNsfbqlL0tO9bMbD9ZKOb4A/Q7JM1XDakg8YoylSKytmx6GH2jcjuTjoFTneajsAHPtHp LLUAFo1MjVSVg9lqjPp/RjEtkUShnj0e9NvORwRDHnJfF5R1Gy3j6/21B7Zd9A== 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 36C0E1BE48; Sun, 27 Mar 2022 20:13:53 +0000 (UTC) (envelope-from git@FreeBSD.org) Received: from gitrepo.freebsd.org ([127.0.1.44]) by gitrepo.freebsd.org (8.16.1/8.16.1) with ESMTP id 22RKDrx5036966; Sun, 27 Mar 2022 20:13:53 GMT (envelope-from git@gitrepo.freebsd.org) Received: (from git@localhost) by gitrepo.freebsd.org (8.16.1/8.16.1/Submit) id 22RKDrEm036965; Sun, 27 Mar 2022 20:13:53 GMT (envelope-from git) Date: Sun, 27 Mar 2022 20:13:53 GMT Message-Id: <202203272013.22RKDrEm036965@gitrepo.freebsd.org> To: src-committers@FreeBSD.org, dev-commits-src-all@FreeBSD.org, dev-commits-src-branches@FreeBSD.org From: "Bjoern A. Zeeb" Subject: git: dd113f67dfb5 - stable/13 - bhyve: Do not remove guest physical addresses from IOMMU host domain 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: bz X-Git-Repository: src X-Git-Refname: refs/heads/stable/13 X-Git-Reftype: branch X-Git-Commit: dd113f67dfb5bdaf5d8b3a87bb19924ad447494c Auto-Submitted: auto-generated ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1648412033; 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=dFu8t5dvOQUhGUezeYP0ozI0il+OFjfuxWGR5OoeHJI=; b=QBdClPB76fOjldhIW2IgsO/nhq7otyyoZfgEJPlf2/Q7yk94cdpG/0zjuSPKyd0PwDQfb3 eDnQmmWNfmC12jQCNYJZ5AWDbkX4AQXjieL8DCOVk6QrTWOJY8zdIMntPDHw0yFTb33wXb 3sfnbCCdfbP+dzKcu9O8KknwM3OKpS5LMBMIUgr4Po2MskrVgiZ/4+pLG6tWGP62OohjUu 1fn08wvs8TMvpkvwTmCaDFzgR1A0OtxTvPWH0kFM2QbLRgwBTk2MHXX32Nr9TNhJAeKO4Z Oam2jCMS70PL3javN+r1U0d/+1EZrXKhbYPqOD/A/8qHnA5biul2F+T+LiYVTg== ARC-Seal: i=1; s=dkim; d=freebsd.org; t=1648412033; a=rsa-sha256; cv=none; b=qGqTWmXHgg1xRSYStsamuDFyBOQQJU28p6U5cMIrVwjd7L7FkJTP7ikCCGM5nWSq5/tBfI p343Wt7DbT+nJV0NLOmryoQzVEZgVWrbw9Ud4vtdkj8DkykXHj3VmXgMZ9TCRIkw66SoFJ 0fSOCS4S1Ep5ZCWZW3N8A9WbnZl8CkUqI7axieRuiNGHGc2ibLUgWb4OWli/YhkVoL1+nj w0U7I5DotIDMcZ2BDr7mKKa9b4Rf2lk643YkqR8CKm7Xu+SJya84YbeccdnYARwppy+HcO zhV7mYeLJCQzzqw/pV3dG4VEvY93W4f8R3mcREhvV8hHKwNHKtma/pPjvDxNsw== ARC-Authentication-Results: i=1; mx1.freebsd.org; none X-ThisMailContainsUnwantedMimeParts: N The branch stable/13 has been updated by bz: URL: https://cgit.FreeBSD.org/src/commit/?id=dd113f67dfb5bdaf5d8b3a87bb19924ad447494c commit dd113f67dfb5bdaf5d8b3a87bb19924ad447494c Author: Bjoern A. Zeeb AuthorDate: 2022-03-18 20:39:06 +0000 Commit: Bjoern A. Zeeb CommitDate: 2022-03-27 17:57:28 +0000 bhyve: Do not remove guest physical addresses from IOMMU host domain This permits I/O devices on the host to directly access wired memory dedicated to guests using passthru devices. Note that wired memory belonging to guests that do not use passthru devices has always been accessible by I/O devices on the host. bhyve maps guest physical addresses into the user address space of the bhyve process by mmap'ing /dev/vmm/. Device models pass pointers derived from this mapping directly to system calls such as preadv() to minimize copies when emulating DMA. If the backing store for a device model is a raw host device (e.g. when exporting a raw disk device such as /dev/ada as a drive in the guest), the host device driver (e.g. ahci for /dev/ada) can itself use DMA on the host directly to the guest's memory. However, if the guest's memory is not present in the host IOMMU domain, these DMA requests by the host device will fail without raising an error visible to the host device driver or to the guest resulting in non-working I/O in the guest. It is unclear why guest addresses were removed from the IOMMU host domain initially, especially only for VM's with a passthru device as the host IOMMU domain does not affect the permissions of passthru devices, only devices on the host. A considered alternative was using bounce buffers instead (D34535 is a proof of concept), but that adds additional overhead for unclear benefit. This solves a long-standing problem when using passthru devices and physical disks in the same VM. Thanks to: grehan (patience and help) Thanks to: jhb (for improving the commit message) PR: 260178, 215740 Reviewed by: grehan, jhb Differential Revision: https://reviews.freebsd.org/D34607 (cherry picked from commit 246c398145674e4a9337fd933a6e6da7f160118e) --- sys/amd64/vmm/vmm.c | 2 -- 1 file changed, 2 deletions(-) diff --git a/sys/amd64/vmm/vmm.c b/sys/amd64/vmm/vmm.c index f0674784903f..5a5744a3fb16 100644 --- a/sys/amd64/vmm/vmm.c +++ b/sys/amd64/vmm/vmm.c @@ -938,10 +938,8 @@ vm_iommu_modify(struct vm *vm, bool map) hpa = DMAP_TO_PHYS((uintptr_t)vp); if (map) { iommu_create_mapping(vm->iommu, gpa, hpa, sz); - iommu_remove_mapping(host_domain, hpa, sz); } else { iommu_remove_mapping(vm->iommu, gpa, sz); - iommu_create_mapping(host_domain, hpa, hpa, sz); } gpa += PAGE_SIZE;