From nobody Mon Jul 01 13:42:22 2024 X-Original-To: dev-commits-src-branches@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 4WCRzz3Qgfz5NhY3; Mon, 01 Jul 2024 13:42:23 +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 4WCRzy6Zgpz4nh8; Mon, 1 Jul 2024 13:42:22 +0000 (UTC) (envelope-from git@FreeBSD.org) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1719841342; 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=cqn38eY2eZ7SRequ0t13x2U8stGyv/Y8rGP5yvYDcRc=; b=FDhD6iAz+UOKwx8k5edefxd9Pvw4JI9jhyCCVH5sIPvPwyzjSoUrK7j9L1nRz4VKIhhKAN Glw/K/Pi0DV1AIRHmBnBOqeuxU/fHtXFNDGJNk9LFbB/R5FNTA1VPhjgFfaNJMS+blOXi0 x3LN4+xGtc2yDTbOtK0xAsaccb4qwljEk2XN70rXgV8CZpL8FEN73PWNl19WHLiAxYOrxE GQlJ19VUcHo/gvFw4bFxqw2L+3j1ah2jS/mh1bNbluyfMdN7j5lCJqDIqZF+CkHIKgsLwp 3O3+JOFHJQM0SDSMOOOVau6n6ODHWNawQm+X5DuubSBiIcFbK+c+qiDN2KpIcw== ARC-Seal: i=1; s=dkim; d=freebsd.org; t=1719841342; a=rsa-sha256; cv=none; b=w+ifT7vZWsHLI3Uw0MKkOOvJ/SM9tn5Zs7CPUp6sQPQowTyMCLVH8EHhtOI113owzRqF53 feMIr8xZJhcVmjd58A8qpxKIwZz1r1cFKJLntDoZU3o16VDC+cW7xmUG8mzYoiQbM/gX+t 8PeyVJHDVJ8XxOJ9Yj872zy2ZXlklMqJKwRdLkg/hefYzIzQc82nXURTjHbA4AeQFUOdFP C+FsoY+xjORwKA2Haxxk77Gd0g/HqvVBiVUkWyKVCVDNr5/lfM4DPQdD/TUF9vSeatOTac kHbRZ7Ekg7Noz8s0vC8Av/1kRdGjCiaaI3yJsQAdgZ08ks3SvXVfRm5aCW1EMg== 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=1719841342; 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=cqn38eY2eZ7SRequ0t13x2U8stGyv/Y8rGP5yvYDcRc=; b=mBYfvLXm9/oPjlYILXY4hl7HgLZfBghfJSoSjSgFl3pJTiasWSzRv5bpTWr7hSl5FsqL5K QGGLYpQmLrc4tXjMEG6XC2qEdKhm/Rlh16i1R9kshmO2YHqchJsdOFDjRePQMvX4qT/xOB CEBFoo2nXkBkf2bs/fHeze8i10P1D4kBZ+2YhxEhBsPTnF2Qe/hMQVYcqi8WBre6n3UZqe eFyhfnCP4UfGTqjVwOeZMlKMAq2RqaiNuNGGBUQIhNQNxntR9I3JrfjEBlT6YTbADTiVS3 KzHzq6O9OgdCH1owT3GzxdySScNWgzNoHW+70iI+Kff+HNQ+8CjyyaGg672PXA== 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 4WCRzy6B83z16Bt; Mon, 1 Jul 2024 13:42:22 +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 461DgMk6027075; Mon, 1 Jul 2024 13:42:22 GMT (envelope-from git@gitrepo.freebsd.org) Received: (from git@localhost) by gitrepo.freebsd.org (8.18.1/8.18.1/Submit) id 461DgM5r027072; Mon, 1 Jul 2024 13:42:22 GMT (envelope-from git) Date: Mon, 1 Jul 2024 13:42:22 GMT Message-Id: <202407011342.461DgM5r027072@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: d56a912f2fb6 - stable/14 - Hyper-V: move memory alloc call for tlb hypercall out of smp_rendezvous List-Id: Commits to the stable branches of the FreeBSD src repository List-Archive: https://lists.freebsd.org/archives/dev-commits-src-branches List-Help: List-Post: List-Subscribe: List-Unsubscribe: X-BeenThere: dev-commits-src-branches@freebsd.org Sender: owner-dev-commits-src-branches@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: d56a912f2fb6fb26a00e950a26e420729e6ef775 Auto-Submitted: auto-generated The branch stable/14 has been updated by whu: URL: https://cgit.FreeBSD.org/src/commit/?id=d56a912f2fb6fb26a00e950a26e420729e6ef775 commit d56a912f2fb6fb26a00e950a26e420729e6ef775 Author: Wei Hu AuthorDate: 2024-06-15 14:07:58 +0000 Commit: Wei Hu CommitDate: 2024-07-01 13:33:08 +0000 Hyper-V: move memory alloc call for tlb hypercall out of smp_rendezvous The allocation call could result in sleep lock violation if it is in smp_rendezvous. Move it out. Also move the pcpu memory pointer to vmbus_pcpu_data since it is only used on Hyper-V. PR: 279738 Reported by: gbe Fixes: 2b887687edc25bb4553f0d8a1183f454a85d413d MFC after: 2 weeks Sponsored by: Microsoft (cherry picked from commit d0cb4674df97aa638d5d17861c364b1625f79401) --- sys/dev/hyperv/vmbus/hyperv_mmu.c | 6 +-- sys/dev/hyperv/vmbus/vmbus.c | 88 +++++++++++++++++++++++++++++---------- sys/dev/hyperv/vmbus/vmbus_var.h | 5 ++- 3 files changed, 71 insertions(+), 28 deletions(-) diff --git a/sys/dev/hyperv/vmbus/hyperv_mmu.c b/sys/dev/hyperv/vmbus/hyperv_mmu.c index 13b1f52fa1f6..7c29fe294093 100644 --- a/sys/dev/hyperv/vmbus/hyperv_mmu.c +++ b/sys/dev/hyperv/vmbus/hyperv_mmu.c @@ -144,7 +144,7 @@ hv_vm_tlb_flush(pmap_t pmap, vm_offset_t addr1, vm_offset_t addr2, return smp_targeted_tlb_shootdown_native(pmap, addr1, addr2, curcpu_cb, op); - flush = *DPCPU_PTR(hv_pcpu_mem); + flush = *VMBUS_PCPU_PTR(sc, cpu_mem, curcpu); if (flush == NULL) return smp_targeted_tlb_shootdown_native(pmap, addr1, addr2, curcpu_cb, op); @@ -253,9 +253,9 @@ hv_flush_tlb_others_ex(pmap_t pmap, vm_offset_t addr1, vm_offset_t addr2, { int nr_bank = 0, max_gvas, gva_n; struct hv_tlb_flush_ex *flush; - if(*DPCPU_PTR(hv_pcpu_mem) == NULL) + if(*VMBUS_PCPU_PTR(sc, cpu_mem, curcpu) == NULL) return EINVAL; - flush = *DPCPU_PTR(hv_pcpu_mem); + flush = *VMBUS_PCPU_PTR(sc, cpu_mem, curcpu); uint64_t status = 0; uint64_t cr3; diff --git a/sys/dev/hyperv/vmbus/vmbus.c b/sys/dev/hyperv/vmbus/vmbus.c index 786b2611dcd7..6a26527768c4 100644 --- a/sys/dev/hyperv/vmbus/vmbus.c +++ b/sys/dev/hyperv/vmbus/vmbus.c @@ -139,7 +139,10 @@ 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; -static void free_pcpu_ptr(void); +#if defined(__x86_64__) +static int vmbus_alloc_cpu_mem(struct vmbus_softc *sc); +static void vmbus_free_cpu_mem(struct vmbus_softc *sc); +#endif SYSCTL_NODE(_hw, OID_AUTO, vmbus, CTLFLAG_RD | CTLFLAG_MPSAFE, NULL, "Hyper-V vmbus"); @@ -217,7 +220,6 @@ static driver_t vmbus_driver = { }; uint32_t hv_max_vp_index; -DPCPU_DEFINE(void *, hv_pcpu_mem); DRIVER_MODULE(vmbus, pcib, vmbus_driver, NULL, NULL); DRIVER_MODULE(vmbus, acpi_syscontainer, vmbus_driver, NULL, NULL); @@ -750,7 +752,6 @@ vmbus_synic_setup(void *xsc) int cpu = curcpu; uint64_t val, orig; uint32_t sint; - void **hv_cpu_mem; if (hyperv_features & CPUID_HV_MSR_VP_INDEX) { /* Save virtual processor id. */ @@ -762,19 +763,6 @@ vmbus_synic_setup(void *xsc) if (VMBUS_PCPU_GET(sc, vcpuid, cpu) > hv_max_vp_index) hv_max_vp_index = VMBUS_PCPU_GET(sc, vcpuid, cpu); - hv_cpu_mem = DPCPU_ID_PTR(cpu, hv_pcpu_mem); - *hv_cpu_mem = contigmalloc(PAGE_SIZE, M_DEVBUF, M_NOWAIT | M_ZERO, - 0ul, ~0ul, PAGE_SIZE, 0); - -#if defined(__x86_64__) - if (*hv_cpu_mem == NULL && hv_tlb_hcall) { - hv_tlb_hcall = 0; - if (bootverbose && sc) - device_printf(sc->vmbus_dev, - "cannot alloc contig memory for hv_pcpu_mem, " - "use system provided tlb flush call.\n"); - } -#endif /* * Setup the SynIC message. @@ -858,7 +846,6 @@ vmbus_synic_teardown(void *arg) */ orig = RDMSR(MSR_HV_SIEFP); WRMSR(MSR_HV_SIEFP, (orig & MSR_HV_SIEFP_RSVD_MASK)); - free_pcpu_ptr(); } static int @@ -1412,15 +1399,41 @@ vmbus_probe(device_t dev) return (BUS_PROBE_DEFAULT); } +#if defined(__x86_64__) +static int +vmbus_alloc_cpu_mem(struct vmbus_softc *sc) +{ + int cpu; -static void free_pcpu_ptr(void) + CPU_FOREACH(cpu) { + void **hv_cpu_mem; + + hv_cpu_mem = VMBUS_PCPU_PTR(sc, cpu_mem, cpu); + *hv_cpu_mem = contigmalloc(PAGE_SIZE, M_DEVBUF, + M_NOWAIT | M_ZERO, 0ul, ~0ul, PAGE_SIZE, 0); + + if (*hv_cpu_mem == NULL) + return ENOMEM; + } + + return 0; +} + +static void +vmbus_free_cpu_mem(struct vmbus_softc *sc) { - int cpu = curcpu; - void **hv_cpu_mem; - hv_cpu_mem = DPCPU_ID_PTR(cpu, hv_pcpu_mem); - if(*hv_cpu_mem) - contigfree(*hv_cpu_mem, PAGE_SIZE, M_DEVBUF); + int cpu; + + CPU_FOREACH(cpu) { + void **hv_cpu_mem; + hv_cpu_mem = VMBUS_PCPU_PTR(sc, cpu_mem, cpu); + if(*hv_cpu_mem != NULL) { + contigfree(*hv_cpu_mem, PAGE_SIZE, M_DEVBUF); + *hv_cpu_mem = NULL; + } + } } +#endif /** * @brief Main vmbus driver initialization routine. @@ -1511,6 +1524,25 @@ vmbus_doattach(struct vmbus_softc *sc) if (ret != 0) goto cleanup; +#if defined(__x86_64__) + /* + * Alloc per cpu memory for tlb flush hypercall + */ + if (hv_tlb_hcall) { + ret = vmbus_alloc_cpu_mem(sc); + if (ret != 0) { + hv_tlb_hcall = 0; + if (bootverbose) + device_printf(sc->vmbus_dev, + "cannot alloc contig memory for " + "cpu_mem, use system provided " + "tlb flush call.\n"); + + vmbus_free_cpu_mem(sc); + } + } +#endif + /* * Setup SynIC. */ @@ -1627,6 +1659,16 @@ vmbus_detach(device_t dev) smp_rendezvous(NULL, vmbus_synic_teardown, NULL, NULL); } +#if defined(__x86_64__) + /* + * Restore the tlb flush to native call + */ + if (hv_tlb_hcall) { + smp_targeted_tlb_shootdown = &smp_targeted_tlb_shootdown_native; + vmbus_free_cpu_mem(sc); + } +#endif + vmbus_intr_teardown(sc); vmbus_dma_free(sc); diff --git a/sys/dev/hyperv/vmbus/vmbus_var.h b/sys/dev/hyperv/vmbus/vmbus_var.h index 4f0668476716..4e0a769402d5 100644 --- a/sys/dev/hyperv/vmbus/vmbus_var.h +++ b/sys/dev/hyperv/vmbus/vmbus_var.h @@ -74,6 +74,9 @@ struct vmbus_pcpu_data { uint32_t vcpuid; /* virtual cpuid */ int event_flags_cnt;/* # of event flags */ struct vmbus_evtflags *event_flags; /* event flags from host */ +#if defined(__x86_64__) + void *cpu_mem; /* For Hyper-V tlb hypercall */ +#endif /* Rarely used fields */ struct taskqueue *event_tq; /* event taskq */ @@ -216,8 +219,6 @@ void vmbus_synic_teardown1(void); int vmbus_setup_intr1(struct vmbus_softc *sc); void vmbus_intr_teardown1(struct vmbus_softc *sc); -DPCPU_DECLARE(void *, hv_pcpu_mem); - extern uint32_t hv_max_vp_index;