From nobody Fri Jun 14 01:21:18 2024 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 4W0hLk3ndPz5N2nQ; Fri, 14 Jun 2024 01:21:18 +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 4W0hLk1Rj6z4VXc; Fri, 14 Jun 2024 01:21:18 +0000 (UTC) (envelope-from git@FreeBSD.org) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1718328078; 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=uKuRpM+N+htlSfH3g7fL+mavSA+u22ASK9EHBIFfcZ0=; b=T3RQQwGZxxQ7qAYKyUgalY6G2IvV6kcopdslzqVv2h9QDgpSzi6K/yrAufG1MTV8t2L3HA bOtyzsh88bNwv4zub1/EnYjNH78QjxR41LqkmcbNSZko3N7zesKgcLWLn4CtVgteHYbBzd UFvOYt9Nc2o707yHhKNA52uH/7uGcMQwvnNIKDgf/q7uwznBKtStARg+EJn590CBdF04Gz PNBekGaYJYVjvc7LHn8Fx9K+/QmvQorjmg571Pce6d8NvG6tnKAKnIoIBewiR3cHMe0lga nr1/N73ng++bH6194wnwrI1bLgnKVbNlmbQyLswqQs5ysjR8d3RgBy3UP/t08w== ARC-Seal: i=1; s=dkim; d=freebsd.org; t=1718328078; a=rsa-sha256; cv=none; b=IA7jIA3np1St0FY+poVyBJAR/gRom3B0Cr14YIevGag48gwTjIYt/Uc4Z1NU6OUHm1IPFq jnwfNgqVNWYypeopS00lWttnUcWroerJOtQmuprbXzlPUNsoSwgx3Q4fc3geC2JUB6lFy/ 01VRfgRBzwijTj5jKuwseQdXM+ndjDY/0P5BJnjNLsewDZCmstKO81Imo6xJzvFuprNaFp UPI8Hoz63JT6SeoUBNdOC8Vk4Y7f5LHngZ7e41NBJPOnbUkqdX1Xl9r/2ZEKS4+oycWUU2 xz6RjsELbOuGzTqld++ig7XMBmVmX/rXIbCBnz3RG3Y1QpzHVWMv8msQSg3iag== 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=1718328078; 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=uKuRpM+N+htlSfH3g7fL+mavSA+u22ASK9EHBIFfcZ0=; b=tWRws/1/HmqlRESHcbs0IZ0BslndSlGOswDMr17A49dxeij+Oq1MPet8QQZix6c2HISAA6 Ueyt6dn9wHVuMj0ajmiyChNgkESOglCictq6NfRm8C5KKdCEhaH4K/YdlgsR04rgEkQBhc 8YpOYlqP9ebTjlygSeXChCxkYBGhcTXCCp0ZsxTBzIF3z6/tug2D/n2h20VQTcHTd5KbbE BkwerZia24OcN9eHDgdJFJlWDEeIcq1xVc2bUnNMcdZxJ/2ow3IoBTS0SEbdm5Fkz8Ovym G0bwJsHHaydHEOt9fMWozMGM2DP+Z6dsnJpSU8bf3f0LSAR5hMBC6B41wvc8lQ== 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 4W0hLk10hpz10Rj; Fri, 14 Jun 2024 01:21:18 +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 45E1LIVE054761; Fri, 14 Jun 2024 01:21:18 GMT (envelope-from git@gitrepo.freebsd.org) Received: (from git@localhost) by gitrepo.freebsd.org (8.17.1/8.17.1/Submit) id 45E1LIQv054758; Fri, 14 Jun 2024 01:21:18 GMT (envelope-from git) Date: Fri, 14 Jun 2024 01:21:18 GMT Message-Id: <202406140121.45E1LIQv054758@gitrepo.freebsd.org> To: src-committers@FreeBSD.org, dev-commits-src-all@FreeBSD.org, dev-commits-src-main@FreeBSD.org From: Mark Johnston Subject: git: 69cbb18746b6 - main - vm_phys: Add a vm_phys_seg_paddr_to_vm_page() helper 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: X-BeenThere: dev-commits-src-main@freebsd.org Sender: owner-dev-commits-src-main@FreeBSD.org MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: 8bit X-Git-Committer: markj X-Git-Repository: src X-Git-Refname: refs/heads/main X-Git-Reftype: branch X-Git-Commit: 69cbb18746b69cbcdf79f1728d0435a1c86fff58 Auto-Submitted: auto-generated The branch main has been updated by markj: URL: https://cgit.FreeBSD.org/src/commit/?id=69cbb18746b69cbcdf79f1728d0435a1c86fff58 commit 69cbb18746b69cbcdf79f1728d0435a1c86fff58 Author: Mark Johnston AuthorDate: 2024-06-14 00:11:36 +0000 Commit: Mark Johnston CommitDate: 2024-06-14 01:18:59 +0000 vm_phys: Add a vm_phys_seg_paddr_to_vm_page() helper No functional change intended. Suggested by: alc Reviewed by: dougm, alc, kib MFC after: 2 weeks Differential Revision: https://reviews.freebsd.org/D43636 --- sys/vm/vm_page.c | 2 +- sys/vm/vm_phys.c | 29 +++++++++++++++++++++-------- sys/vm/vm_phys.h | 1 + 3 files changed, 23 insertions(+), 9 deletions(-) diff --git a/sys/vm/vm_page.c b/sys/vm/vm_page.c index 3077b023754a..37149cb660cb 100644 --- a/sys/vm/vm_page.c +++ b/sys/vm/vm_page.c @@ -782,7 +782,7 @@ vm_page_startup(vm_offset_t vaddr) if (pagecount == 0) continue; - m = seg->first_page + atop(startp - seg->start); + m = vm_phys_seg_paddr_to_vm_page(seg, startp); vmd = VM_DOMAIN(seg->domain); vm_domain_free_lock(vmd); vm_phys_enqueue_contig(m, pagecount); diff --git a/sys/vm/vm_phys.c b/sys/vm/vm_phys.c index 6323fb484030..35e544708c84 100644 --- a/sys/vm/vm_phys.c +++ b/sys/vm/vm_phys.c @@ -932,6 +932,19 @@ vm_phys_alloc_freelist_pages(int domain, int freelist, int pool, int order) return (NULL); } +/* + * Find the vm_page corresponding to the given physical address, which must lie + * within the given physical memory segment. + */ +vm_page_t +vm_phys_seg_paddr_to_vm_page(struct vm_phys_seg *seg, vm_paddr_t pa) +{ + KASSERT(pa >= seg->start && pa < seg->end, + ("%s: pa %#jx is out of range", __func__, (uintmax_t)pa)); + + return (&seg->first_page[atop(pa - seg->start)]); +} + /* * Find the vm_page corresponding to the given physical address. */ @@ -941,7 +954,7 @@ vm_phys_paddr_to_vm_page(vm_paddr_t pa) struct vm_phys_seg *seg; if ((seg = vm_phys_paddr_to_seg(pa)) != NULL) - return (&seg->first_page[atop(pa - seg->start)]); + return (vm_phys_seg_paddr_to_vm_page(seg, pa)); return (NULL); } @@ -1157,7 +1170,7 @@ vm_phys_free_pages(vm_page_t m, int order) pa ^= ((vm_paddr_t)1 << (PAGE_SHIFT + order)); if (pa < seg->start || pa >= seg->end) break; - m_buddy = &seg->first_page[atop(pa - seg->start)]; + m_buddy = vm_phys_seg_paddr_to_vm_page(seg, pa); if (m_buddy->order != order) break; fl = (*seg->free_queues)[m_buddy->pool]; @@ -1166,7 +1179,7 @@ vm_phys_free_pages(vm_page_t m, int order) vm_phys_set_pool(m->pool, m_buddy, order); order++; pa &= ~(((vm_paddr_t)1 << (PAGE_SHIFT + order)) - 1); - m = &seg->first_page[atop(pa - seg->start)]; + m = vm_phys_seg_paddr_to_vm_page(seg, pa); } while (order < VM_NFREEORDER - 1); } fl = (*seg->free_queues)[m->pool]; @@ -1278,8 +1291,8 @@ vm_phys_find_range(vm_page_t bounds[], int segind, int domain, pa_end = MIN(high, seg->end); if (pa_end - pa_start < ptoa(npages)) continue; - bounds[0] = &seg->first_page[atop(pa_start - seg->start)]; - bounds[1] = &seg->first_page[atop(pa_end - seg->start)]; + bounds[0] = vm_phys_seg_paddr_to_vm_page(seg, pa_start); + bounds[1] = vm_phys_seg_paddr_to_vm_page(seg, pa_end); return (seg - vm_phys_segs); } return (-1); @@ -1313,7 +1326,7 @@ vm_phys_unfree_page(vm_page_t m) order++; pa = m->phys_addr & (~(vm_paddr_t)0 << (PAGE_SHIFT + order)); if (pa >= seg->start) - m_set = &seg->first_page[atop(pa - seg->start)]; + m_set = vm_phys_seg_paddr_to_vm_page(seg, pa); else return (false); } @@ -1338,10 +1351,10 @@ vm_phys_unfree_page(vm_page_t m) order--; pa_half = m_set->phys_addr ^ (1 << (PAGE_SHIFT + order)); if (m->phys_addr < pa_half) - m_tmp = &seg->first_page[atop(pa_half - seg->start)]; + m_tmp = vm_phys_seg_paddr_to_vm_page(seg, pa_half); else { m_tmp = m_set; - m_set = &seg->first_page[atop(pa_half - seg->start)]; + m_set = vm_phys_seg_paddr_to_vm_page(seg, pa_half); } vm_freelist_add(fl, m_tmp, order, 0); } diff --git a/sys/vm/vm_phys.h b/sys/vm/vm_phys.h index 1f502ad745c4..300443accdb6 100644 --- a/sys/vm/vm_phys.h +++ b/sys/vm/vm_phys.h @@ -77,6 +77,7 @@ void vm_phys_free_contig(vm_page_t m, u_long npages); void vm_phys_free_pages(vm_page_t m, int order); void vm_phys_init(void); vm_page_t vm_phys_paddr_to_vm_page(vm_paddr_t pa); +vm_page_t vm_phys_seg_paddr_to_vm_page(struct vm_phys_seg *seg, vm_paddr_t pa); void vm_phys_register_domains(int ndomains, struct mem_affinity *affinity, int *locality); bool vm_phys_unfree_page(vm_page_t m);