From nobody Thu Sep 14 07:22:02 2023 X-Original-To: dev-commits-src-main@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 4RmTKR0y3Mz4tgG7; Thu, 14 Sep 2023 07:22:03 +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 4RmTKR0WB0z3WSP; Thu, 14 Sep 2023 07:22:03 +0000 (UTC) (envelope-from git@FreeBSD.org) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1694676123; 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=MutLbhSx+YhUj5O3k16mp82jAmY4XKIqLqd96pRdNGQ=; b=gknXaB4P5MnIL06XUnQ4tiY1QuA8enh7Q3m6neaJXWknoT3uc+Fe/Jyxqk4i/obWki0Y9I P4TKJRL/hj1MfFnMv61gUOwFFGhltK3KgsmE6omNYTLmHzKPcAcAVT9ogITYeERCOv09T0 p25joEAmtwEdrgx0gbIcUaTWDKbGlD3hFr935QxAjSu6zVd/IAOZRUvlFPeeKFrul/J7m1 SX9cwjKldrQrGgDw6+0wblYRn0DNKvU5Cq4CmX4ESu2pYbuzjodO2NFOViU3ClnaBZQ6Vd 7ohJox/zIBYDyLW1KWh6+SXwxwvKQx03oK1iE4fFwl+xe3N6U9M/g5jcwTMHww== ARC-Seal: i=1; s=dkim; d=freebsd.org; t=1694676123; a=rsa-sha256; cv=none; b=IrByh7m1n244EIdm0QlKYb3Lo9pBV/vP1Yz1e0CWVUaxZUAcL80M6Bps7SGT+sWn3L3Guw GKg+23FsC72Q2vRkv+StdQnNl+OBhXyvfmOvyEbVmflFBMQKerxpMWZJiG0szdmqxwlaN6 w+S3D9Xb/ff+RfxCRZXajb+MhXLRZnVYI1MDGRlK+4m6EqHpYvpPJMXRdDGps81NY+Tfdz vIGTmahg4vABb/4gk8ZV8GXKPP8E/4tFgEft42wW+Z9BueDhT2m9Wji28DGqaL/3ZRnvQL Izxr31PIVLYfzUr+7CMmWU35wndjLbZlQtkeNGOUT4qUgYMLOTrq410nZDJR/Q== 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=1694676123; 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=MutLbhSx+YhUj5O3k16mp82jAmY4XKIqLqd96pRdNGQ=; b=PyCuKeOgwXCA9YMXnhfll3Dl4lqSQmj8ud5FnHjgAV2KhZnsOBJJibTnFJLUJsF0IORdEL CxNSio5ujn9Z1PFQnqrakx7lhMhh3k7/8OvniPKNl02fMiE3iDmL1lQe0vSmgYksr7LTCL 5IYIc2LZFrVj9e7DY7SSK+FB+MOaqMFoanbCP/MbFwBdOZ8lHJSWB2XYr0kPKxg/+AzF7i +Gh3x0KhZnd6Jc0JrRpRl1aEcR0s0zIdaGTOJ+3yx+8HSWvCO0mD8W80AkXGezrnS/W+3e atBbZnRyYs0Igpom70kp7f+s/dnr0l3Z3pZdzKHOohjOWCGHz95cXssDSMx+JA== 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 4RmTKQ6N6Jznjt; Thu, 14 Sep 2023 07:22:02 +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 38E7M2Mq023528; Thu, 14 Sep 2023 07:22:02 GMT (envelope-from git@gitrepo.freebsd.org) Received: (from git@localhost) by gitrepo.freebsd.org (8.17.1/8.17.1/Submit) id 38E7M2tN023525; Thu, 14 Sep 2023 07:22:02 GMT (envelope-from git) Date: Thu, 14 Sep 2023 07:22:02 GMT Message-Id: <202309140722.38E7M2tN023525@gitrepo.freebsd.org> To: src-committers@FreeBSD.org, dev-commits-src-all@FreeBSD.org, dev-commits-src-main@FreeBSD.org From: Wei Hu Subject: git: e7a9817b8d32 - main - Hyper-V: vmbus: implementat bus_get_dma_tag in vmbus List-Id: Commit messages for the main branch of the src repository List-Archive: https://lists.freebsd.org/archives/dev-commits-src-main List-Help: List-Post: List-Subscribe: List-Unsubscribe: Sender: owner-dev-commits-src-main@freebsd.org X-BeenThere: dev-commits-src-main@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/main X-Git-Reftype: branch X-Git-Commit: e7a9817b8d328dda04069b65944ce2ed6f54c6f0 Auto-Submitted: auto-generated The branch main has been updated by whu: URL: https://cgit.FreeBSD.org/src/commit/?id=e7a9817b8d328dda04069b65944ce2ed6f54c6f0 commit e7a9817b8d328dda04069b65944ce2ed6f54c6f0 Author: Souradeep Chakrabarti AuthorDate: 2023-09-14 07:11:25 +0000 Commit: Wei Hu CommitDate: 2023-09-14 07:11:25 +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 --- 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 */