From nobody Mon Sep 18 14:59:56 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 4Rq7Hw69wtz4tKcn; Mon, 18 Sep 2023 14:59:56 +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 4Rq7Hw562cz4fmh; Mon, 18 Sep 2023 14:59:56 +0000 (UTC) (envelope-from git@FreeBSD.org) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1695049196; 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=1ba+QmhwCuDwgkFRgftFA/0pXboaUhUiWNR18lMaJac=; b=cpz8w9381hOC8mjH+1dZ6p7HhwReuS8nQK2w43RS+L5+vRSFqJem7HC/EFASmpT2isXRf4 Dm1U6aKgeOU8GCkFv/MRtL6O2d7Mr8r4lGS8S64XWDhH1pIaD/WY7HD+dHVa7sJNOTEFmm XlqQ8wF7gEOPhT4rJ03xWc6ZnAvwgbkA4Amk2izZg9pKcKg5zJTBA8/YG/jAijCgsZKcZK uGLaiIMLe1vF3fm/ZZl52vcGJX4M1DvCElFTk2Z4eMCP/vg86Wml1LKOceEqfUMj9Upw8X 071L2VrIZldASag1qCw0kwvua8kz10+KRgPE+dxMqW2ZswVSRnbRRHYKLlCRKg== ARC-Seal: i=1; s=dkim; d=freebsd.org; t=1695049196; a=rsa-sha256; cv=none; b=poPOZwdjWhv5HkVWLBmXF/Nypt9ZOqAwKOGWy3PrMyFHupphqe3hItOYUEYata28y0nh7u bkfjKModGb5dujWBDGQhjJ5QJ8fv2Kdj6Ez015XeVF5dtwt6S4DJbXk+CxfDpibbkVxXC+ YvlTmOKqXhee8HQ0eO4aTTweZw4pNox9fTSZ4fVUJvXaMaY7A31Zo/EblRIcAprRFTGhqh AmGZU4sev+4SWvQhnzjoaZ4Hu4ok4oumI1lPr7Zc9WCR02AmY0A4bB7bhPSCGN5JmgMIkk +/Hi155QsxHTMv8IFtO24P24vFaWvYmFACg5n+nK66xP82N3fJdmCRD2ML1pMw== ARC-Authentication-Results: i=1; mx1.freebsd.org; none ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1695049196; 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=1ba+QmhwCuDwgkFRgftFA/0pXboaUhUiWNR18lMaJac=; b=RMRnHVBq2DetlENAGrdsl4epimpG1TW355WOnTg4yVFTcCPbrjJAMfyfp7iP6L6sBzm0vy L0sV/n+e/2BfQ9YoUVtK6EuHEuzKFlX3+xehv5DKppzh2KMpCFa2WtxvNkK/lAA2QwV9fn +2nI8I6gfoMzki2NPdjy1Kaf82HBxvX7Isc8HqbNPPzctq/3mD/w4f5ehnDsstUkYGXso0 CVTx3M147ACmxyQUfw2pJ+b46s6rEyceMXJ+WGf5eyIvRYZf592+FagqDhf81kDP8J2lpr LO3tAL5PKEOjLid6KZl5mOKpoBTpXGCV+vzYX4LACO8jKAtKmwkAk24EsI1LVQ== 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 4Rq7Hw3TxXzbG3; Mon, 18 Sep 2023 14:59:56 +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 38IExudu047254; Mon, 18 Sep 2023 14:59:56 GMT (envelope-from git@gitrepo.freebsd.org) Received: (from git@localhost) by gitrepo.freebsd.org (8.17.1/8.17.1/Submit) id 38IExuro047251; Mon, 18 Sep 2023 14:59:56 GMT (envelope-from git) Date: Mon, 18 Sep 2023 14:59:56 GMT Message-Id: <202309181459.38IExuro047251@gitrepo.freebsd.org> To: src-committers@FreeBSD.org, dev-commits-src-all@FreeBSD.org, dev-commits-src-branches@FreeBSD.org From: Wei Hu Subject: git: 48a799af88c0 - releng/14.0 - Hyper-V: vmbus: implementat bus_get_dma_tag in vmbus 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: whu X-Git-Repository: src X-Git-Refname: refs/heads/releng/14.0 X-Git-Reftype: branch X-Git-Commit: 48a799af88c0c77963ffb23eba797f85f86751dd Auto-Submitted: auto-generated The branch releng/14.0 has been updated by whu: URL: https://cgit.FreeBSD.org/src/commit/?id=48a799af88c0c77963ffb23eba797f85f86751dd commit 48a799af88c0c77963ffb23eba797f85f86751dd Author: Souradeep Chakrabarti AuthorDate: 2023-09-14 07:11:25 +0000 Commit: Wei Hu CommitDate: 2023-09-18 14:57:57 +0000 Hyper-V: vmbus: implementat bus_get_dma_tag in vmbus In ARM64 Hyper-V UFS filesystem is getting corruption and those corruptions are consistently happening just after hitting a page boundary. It is unable to correctly read disk blocks into buffers that are not aligned to 512-byte boundaries. It happens because storvsc needs physically contiguous memory which may not be the case when bus_dma needs to create a bounce buffer. This can happen when the destination is not cache-line aligned. Hyper-V VMs have VMbus synthetic devices and PCI pass-thru devices that are added dynamically via the VMbus protocol and are not represented in the ACPI DSDT. Only the top level VMbus node exists in the DSDT. As such, on ARM64 these devices don't pick up coherence information and default to not hardware coherent. Approved by: re (gjb) PR: 267654, 272666 Reviewed by: andrew, whu Tested by: lwhsu Sponsored by: Microsoft Differential Revision: https://reviews.freebsd.org/D41728 (cherry picked from commit e7a9817b8d328dda04069b65944ce2ed6f54c6f0) (cherry picked from commit 85bc81352e4b0d0a9da251bacec35eec130eee49) --- sys/dev/hyperv/vmbus/vmbus.c | 33 +++++++++++++++++++++++++++++++++ sys/dev/hyperv/vmbus/vmbus_var.h | 1 + 2 files changed, 34 insertions(+) diff --git a/sys/dev/hyperv/vmbus/vmbus.c b/sys/dev/hyperv/vmbus/vmbus.c index e0f7bbc99ca7..ee412e643b4f 100644 --- a/sys/dev/hyperv/vmbus/vmbus.c +++ b/sys/dev/hyperv/vmbus/vmbus.c @@ -137,6 +137,7 @@ static void vmbus_intr_teardown(struct vmbus_softc *); static int vmbus_doattach(struct vmbus_softc *); static void vmbus_event_proc_dummy(struct vmbus_softc *, int); +static bus_dma_tag_t vmbus_get_dma_tag(device_t parent, device_t child); static struct vmbus_softc *vmbus_sc; SYSCTL_NODE(_hw, OID_AUTO, vmbus, CTLFLAG_RD | CTLFLAG_MPSAFE, NULL, @@ -183,6 +184,7 @@ static device_method_t vmbus_methods[] = { DEVMETHOD(bus_setup_intr, bus_generic_setup_intr), DEVMETHOD(bus_teardown_intr, bus_generic_teardown_intr), DEVMETHOD(bus_get_cpus, bus_generic_get_cpus), + DEVMETHOD(bus_get_dma_tag, vmbus_get_dma_tag), /* pcib interface */ DEVMETHOD(pcib_alloc_msi, vmbus_alloc_msi), @@ -219,6 +221,13 @@ vmbus_get_softc(void) return vmbus_sc; } +static bus_dma_tag_t +vmbus_get_dma_tag(device_t dev, device_t child) +{ + struct vmbus_softc *sc = vmbus_get_softc(); + return (sc->dmat); +} + void vmbus_msghc_reset(struct vmbus_msghc *mh, size_t dsize) { @@ -1382,6 +1391,9 @@ vmbus_doattach(struct vmbus_softc *sc) struct sysctl_oid_list *child; struct sysctl_ctx_list *ctx; int ret; + device_t dev_res; + ACPI_HANDLE handle; + unsigned int coherent; if (sc->vmbus_flags & VMBUS_FLAG_ATTACHED) return (0); @@ -1402,6 +1414,27 @@ vmbus_doattach(struct vmbus_softc *sc) sizeof(struct vmbus_channel *) * VMBUS_CHAN_MAX, M_DEVBUF, M_WAITOK | M_ZERO); + /* Coherency attribute */ + dev_res = devclass_get_device(devclass_find("vmbus_res"), 0); + handle = acpi_get_handle(dev_res); + + if (ACPI_FAILURE(acpi_GetInteger(handle, "_CCA", &coherent))) + coherent = 0; + if (bootverbose) + device_printf(sc->vmbus_dev, "Bus is%s cache-coherent\n", + coherent ? "" : " not"); + + bus_dma_tag_create(bus_get_dma_tag(sc->vmbus_dev), + 1, 0, + BUS_SPACE_MAXADDR, + BUS_SPACE_MAXADDR, + NULL, NULL, + BUS_SPACE_MAXSIZE, + BUS_SPACE_UNRESTRICTED, + BUS_SPACE_MAXSIZE, + coherent ? BUS_DMA_COHERENT : 0, + NULL, NULL, + &sc->dmat); /* * Create context for "post message" Hypercalls */ diff --git a/sys/dev/hyperv/vmbus/vmbus_var.h b/sys/dev/hyperv/vmbus/vmbus_var.h index f6fc875deb32..023d27c52cea 100644 --- a/sys/dev/hyperv/vmbus/vmbus_var.h +++ b/sys/dev/hyperv/vmbus/vmbus_var.h @@ -129,6 +129,7 @@ struct vmbus_softc { void *icookie; int vector; #endif + bus_dma_tag_t dmat; }; #define VMBUS_FLAG_ATTACHED 0x0001 /* vmbus was attached */