From nobody Fri Nov 18 18:26:39 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 4NDQGl4ys1z4d87d; Fri, 18 Nov 2022 18:26:39 +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 4NDQGl3bk6z4JFx; Fri, 18 Nov 2022 18:26:39 +0000 (UTC) (envelope-from git@FreeBSD.org) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1668795999; 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=3IhApYIH7eoUO9haZpSsqVtaLB/2vSoe6GlYNmpAlss=; b=FgByUruogslHhrxeXBUx83eyfxurBBYHFHsFcd1Z2IG0hTgELSZ2BkAFSZc3ZXN2eepQ8u cfJCh3NFC6ySIUWWRNt/CSe/KHXOpmRPqgrSb0O6Mc0YOlWrCNCHPyZSkZsDLsrMzYyA8q j9I5gfHv9315+Xx3nffIf+U0xIeIoHP654T68jyw6eF2xtbyJyBDevP2g6pzfDdJCFk2xk 0OcYpljJqjzxdETVi5dZiCFa9ey6EAZF9FR2atka6yr2XkfYi+yVPLOXyQtstjj26/E+fF G6mg5AGsggDSiB2IKif6KmOINT9c1V2JBCft1bK2teqOiZmOYN57PX1+R4YDTg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1668795999; 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=3IhApYIH7eoUO9haZpSsqVtaLB/2vSoe6GlYNmpAlss=; b=QfGMt+JOrGUPXo/K/nmn5zPej8Tmx4U9hg9BIicMSSX5EO7Fk5jF59keIzcQyYZQCQx1Vs qi15c+P+kaa01Tq1NR1bosEYhXYFTC5atoHy6vMFkWIh5z2a6zxppS9PPf81YeWV6wn4VO MEH6KB0B70RcxbTGNCtjEsLmMYGtUvbeEz1kbUoYykIlqaCDn0WL/21lCgbDgNsERHIObo oMd7oX6NpTtwj8tnjRG2dDwBgfCkpjpSjAt0GMb5lXfQhhgz1yG1OVD+oqydTcnj7Qrz58 peUxImpuCbOpxN23Rs8O+EwfPfyCAejZXTjjNtP1SQcHZjNB+opscK1JxtN19Q== ARC-Authentication-Results: i=1; mx1.freebsd.org; none ARC-Seal: i=1; s=dkim; d=freebsd.org; t=1668795999; a=rsa-sha256; cv=none; b=dBaAdweREB+G5tPrMCVM+S7uAKuhgupU09W6JTQN16xGSJ/X0zd3ACCLH3yGMPAEQoNGhN bPG9WWA56LTPG57uOB2ZpiyfKv29yiLQELXXIiYJN6Y89m4UwMAi1jrNcbmjuPxFdLkDCB VrWnRF3PLxj1IE6nS10lHLebGO8yXbLN85mpiXHnIK/JBwN3akpBupsN7iqj+koZeRCIDw AMwSIMFzg47nHR/ZIPXegL7I/qaJ4NM2Feff925TFWBt/obZRae+UYszymFYEUcSwPR2Zt dmYhD5ZmVoVZPhzpWM1yFiAedZfaNCF5p+Xs0z4DTMskAKMjR7VzeA8TcCkSSA== 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 4NDQGl2TRlzG5J; Fri, 18 Nov 2022 18:26:39 +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 2AIIQd3c030304; Fri, 18 Nov 2022 18:26:39 GMT (envelope-from git@gitrepo.freebsd.org) Received: (from git@localhost) by gitrepo.freebsd.org (8.16.1/8.16.1/Submit) id 2AIIQdlO030303; Fri, 18 Nov 2022 18:26:39 GMT (envelope-from git) Date: Fri, 18 Nov 2022 18:26:39 GMT Message-Id: <202211181826.2AIIQdlO030303@gitrepo.freebsd.org> To: src-committers@FreeBSD.org, dev-commits-src-all@FreeBSD.org, dev-commits-src-main@FreeBSD.org From: John Baldwin Subject: git: 28b561ad9d03 - main - vmm: Add vm_gpa_hold_global wrapper function. 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: jhb X-Git-Repository: src X-Git-Refname: refs/heads/main X-Git-Reftype: branch X-Git-Commit: 28b561ad9d03617418aed33b9b8c1311e940f0c8 Auto-Submitted: auto-generated X-ThisMailContainsUnwantedMimeParts: N The branch main has been updated by jhb: URL: https://cgit.FreeBSD.org/src/commit/?id=28b561ad9d03617418aed33b9b8c1311e940f0c8 commit 28b561ad9d03617418aed33b9b8c1311e940f0c8 Author: John Baldwin AuthorDate: 2022-11-18 18:01:57 +0000 Commit: John Baldwin CommitDate: 2022-11-18 18:25:36 +0000 vmm: Add vm_gpa_hold_global wrapper function. This handles the case that guest pages are being held not on behalf of a virtual CPU but globally. Previously this was handled by passing a vcpuid of -1 to vm_gpa_hold, but that will not work in the future when vm_gpa_hold is changed to accept a struct vcpu pointer. Reviewed by: corvink, markj Differential Revision: https://reviews.freebsd.org/D37160 --- sys/amd64/include/vmm.h | 2 ++ sys/amd64/vmm/vmm.c | 64 ++++++++++++++++++++++++++++++++----------------- 2 files changed, 44 insertions(+), 22 deletions(-) diff --git a/sys/amd64/include/vmm.h b/sys/amd64/include/vmm.h index a223eb17afe9..3e7dbf59fc0d 100644 --- a/sys/amd64/include/vmm.h +++ b/sys/amd64/include/vmm.h @@ -253,6 +253,8 @@ int vm_get_memseg(struct vm *vm, int ident, size_t *len, bool *sysmem, vm_paddr_t vmm_sysmem_maxaddr(struct vm *vm); void *vm_gpa_hold(struct vm *, int vcpuid, vm_paddr_t gpa, size_t len, int prot, void **cookie); +void *vm_gpa_hold_global(struct vm *vm, vm_paddr_t gpa, size_t len, + int prot, void **cookie); void vm_gpa_release(void *cookie); bool vm_mem_allocated(struct vm *vm, int vcpuid, vm_paddr_t gpa); diff --git a/sys/amd64/vmm/vmm.c b/sys/amd64/vmm/vmm.c index bffba382b667..a428534b8737 100644 --- a/sys/amd64/vmm/vmm.c +++ b/sys/amd64/vmm/vmm.c @@ -965,8 +965,8 @@ vm_iommu_modify(struct vm *vm, bool map) gpa = mm->gpa; while (gpa < mm->gpa + mm->len) { - vp = vm_gpa_hold(vm, -1, gpa, PAGE_SIZE, VM_PROT_WRITE, - &cookie); + vp = vm_gpa_hold_global(vm, gpa, PAGE_SIZE, + VM_PROT_WRITE, &cookie); KASSERT(vp != NULL, ("vm(%s) could not map gpa %#lx", vm_name(vm), gpa)); @@ -1032,30 +1032,14 @@ vm_assign_pptdev(struct vm *vm, int bus, int slot, int func) return (error); } -void * -vm_gpa_hold(struct vm *vm, int vcpuid, vm_paddr_t gpa, size_t len, int reqprot, - void **cookie) +static void * +_vm_gpa_hold(struct vm *vm, vm_paddr_t gpa, size_t len, int reqprot, + void **cookie) { int i, count, pageoff; struct mem_map *mm; vm_page_t m; -#ifdef INVARIANTS - /* - * All vcpus are frozen by ioctls that modify the memory map - * (e.g. VM_MMAP_MEMSEG). Therefore 'vm->memmap[]' stability is - * guaranteed if at least one vcpu is in the VCPU_FROZEN state. - */ - int state; - KASSERT(vcpuid >= -1 && vcpuid < vm->maxcpus, ("%s: invalid vcpuid %d", - __func__, vcpuid)); - for (i = 0; i < vm->maxcpus; i++) { - if (vcpuid != -1 && vcpuid != i) - continue; - state = vcpu_get_state(vm, i, NULL); - KASSERT(state == VCPU_FROZEN, ("%s: invalid vcpu state %d", - __func__, state)); - } -#endif + pageoff = gpa & PAGE_MASK; if (len > PAGE_SIZE - pageoff) panic("vm_gpa_hold: invalid gpa/len: 0x%016lx/%lu", gpa, len); @@ -1079,6 +1063,42 @@ vm_gpa_hold(struct vm *vm, int vcpuid, vm_paddr_t gpa, size_t len, int reqprot, } } +void * +vm_gpa_hold(struct vm *vm, int vcpuid, vm_paddr_t gpa, size_t len, int reqprot, + void **cookie) +{ +#ifdef INVARIANTS + /* + * The current vcpu should be frozen to ensure 'vm_memmap[]' + * stability. + */ + int state = vcpu_get_state(vm, vcpuid, NULL); + KASSERT(state == VCPU_FROZEN, ("%s: invalid vcpu state %d", + __func__, state)); +#endif + return (_vm_gpa_hold(vm, gpa, len, reqprot, cookie)); +} + +void * +vm_gpa_hold_global(struct vm *vm, vm_paddr_t gpa, size_t len, int reqprot, + void **cookie) +{ +#ifdef INVARIANTS + /* + * All vcpus are frozen by ioctls that modify the memory map + * (e.g. VM_MMAP_MEMSEG). Therefore 'vm->memmap[]' stability is + * guaranteed if at least one vcpu is in the VCPU_FROZEN state. + */ + int state; + for (int i = 0; i < vm->maxcpus; i++) { + state = vcpu_get_state(vm, i, NULL); + KASSERT(state == VCPU_FROZEN, ("%s: invalid vcpu state %d", + __func__, state)); + } +#endif + return (_vm_gpa_hold(vm, gpa, len, reqprot, cookie)); +} + void vm_gpa_release(void *cookie) {