From nobody Mon Sep 18 10:38:26 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 4Rq1VB3FQVz4syLx; Mon, 18 Sep 2023 10:38:26 +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 4Rq1VB2Srzz3XS9; Mon, 18 Sep 2023 10:38:26 +0000 (UTC) (envelope-from git@FreeBSD.org) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1695033506; 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=jP0K3yH2EhpOlT2XjGT8/NkdiFzuUPDrGl38v/XCGpc=; b=OLjKukkPOG7H0HjNTdu4Ue17g/m4N9Mgt+6BMwGhC7vYHUosdb02wIQC83FcqLgT2IW7px oNuM9S7b7QKj91SVurqsP3ow9YQCxu1Q7Ye4ZWWc/FA7GJWRt8LpmlA/hBt5kQSkU/g1JC 7W7N+/jLhUHpAI1c5YqzTNU8NIP8etuEW8/GBLqqNtZLQyPf5kH4jjbso8Mm2gN0vq97/x Xr3xNNks3mkl2eiHT2/p9d4JA54xbwVPn3oUdYKoBWL0ag0kvXo3+ejjjXOyZHm3BkcMh2 WgBeBYJgkTbNZnrT0nAH0ELSOomlVOwH5wiY3h9gCc/WigeLQNzIm01muTI0Zw== ARC-Seal: i=1; s=dkim; d=freebsd.org; t=1695033506; a=rsa-sha256; cv=none; b=otO2AebYxGlue143od3v1kdWEXKBa+YIQ1yjEj1/xPYyJdrS1JsxHZ+jXEGMOVOlK5FJSD VY8cBN0DW/b912qJqgI2XX/cmxgZIp9T3yERyzH0tQ5hHDMbFsFBWLLyaNNzuRZVsDA1kp iIHZcXS/SHbjx5tcXa1yD4C8vOy1oIApHLaQ+qmMNQucTXLIeyv2MMOU/UdF9uFAN7lePO K9+Ass9VRnbNUkg0Syqyhho85/hoUIgCRY0f2aIwzayFNrchM0/F420HaAOsx6dwRYjXCv D4QAM2IvkiUc2DQhMjf/shbfLtFgSV7B/MY51qFO3RkZgM5gwP9SeXUksh42RQ== 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=1695033506; 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=jP0K3yH2EhpOlT2XjGT8/NkdiFzuUPDrGl38v/XCGpc=; b=wYjTQz/xGfIVZI3F4Dp3nH9XxfKCO5F1OqM0W/t7/qQmmdK4GKgLclE/HLqNEzNtZ0Rykx NP5fsToF056CYKhtD8zZL8EiflUY6i51OBpsojwO+GDa3ZY6oKU8AejPAn3xQIXXEGoqsm BIxHuUThA8rJ6kJrLeGXY63dGC/gn1bgdQk6OTq32yb1neZuTi8pstrrHvOS4FYrCig+ZB wDA697F3zuOWbkfDiA7SEslBzU9Mm65QU1T6nNuh1xifVrz78CLHc8MWwkKW34B/LxTW2V 5tIMgKmdbA3nT+zglQFiPYcnMxw/vq1JQJTQjuM0W0zjYUbzPpG75y1GM/w7eA== 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 4Rq1VB1Ym9zClk; Mon, 18 Sep 2023 10:38:26 +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 38IAcQoO013894; Mon, 18 Sep 2023 10:38:26 GMT (envelope-from git@gitrepo.freebsd.org) Received: (from git@localhost) by gitrepo.freebsd.org (8.17.1/8.17.1/Submit) id 38IAcQDJ013891; Mon, 18 Sep 2023 10:38:26 GMT (envelope-from git) Date: Mon, 18 Sep 2023 10:38:26 GMT Message-Id: <202309181038.38IAcQDJ013891@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: 85bc81352e4b - stable/14 - 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/stable/14 X-Git-Reftype: branch X-Git-Commit: 85bc81352e4b0d0a9da251bacec35eec130eee49 Auto-Submitted: auto-generated The branch stable/14 has been updated by whu: URL: https://cgit.FreeBSD.org/src/commit/?id=85bc81352e4b0d0a9da251bacec35eec130eee49 commit 85bc81352e4b0d0a9da251bacec35eec130eee49 Author: Souradeep Chakrabarti AuthorDate: 2023-09-14 07:11:25 +0000 Commit: Wei Hu CommitDate: 2023-09-18 10:26:59 +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. PR: 267654, 272666 Reviewed by: andrew, whu Tested by: lwhsu MFC after: 3 days Sponsored by: Microsoft Differential Revision: https://reviews.freebsd.org/D41728 (cherry picked from commit e7a9817b8d328dda04069b65944ce2ed6f54c6f0) --- 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 */