From nobody Wed Feb 19 14:14:21 2025 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 4YydgK63XNz5pQDK; Wed, 19 Feb 2025 14:14:21 +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 4YydgK4GV1z3n3g; Wed, 19 Feb 2025 14:14:21 +0000 (UTC) (envelope-from git@FreeBSD.org) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1739974461; 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=DMEPU0KmasMuOmpm0B0TofD9lwikxK2cj/ZUd2ljEV8=; b=wcSYOv5v/q5p/Sfzv8UtZpPZs8FJvB/+4ikFqFxMjpd31jpEkMJyD+T0CXDRHpkBvROyPz w/8ig8OMb/z7HOWbVirvSoB2VrwlLl5H4P5Ukz6D+JZx2qxHyXpwILXxzYRrxw4NR+XXtu KyZcto6wL0KC7d/psdN3/SSqco4uBjRyAGtsEG5KGy6JjijKuSC6fHdjEO88PqoCO8XeRG UJu+TE5cPM6CK8lxpeZAAtSYOESimKBnshafAsSwFSgcnEoLDVasjZU9HiLFoSYRIC2mzT TSs9BxETnE569cIAEhym32UGDyn/+Efstga7o3myK7cJ1euUUDtEPgL8ht5IPA== ARC-Seal: i=1; s=dkim; d=freebsd.org; t=1739974461; a=rsa-sha256; cv=none; b=k/GDdeLrqnbDDD21aXjJSoEBWpyBUg8JUOEgbJzy4K3x6nOGZrv0lXb4Am3NNZVJo8FAfR WsVfoAMTUPBrsUWjgdSe++6vE+GitxtRxaMTm0oN7604SC139A0+LB9q/+idNnpZxLQ9Lz 3EXQiDtVMJNR9bUf/17A45fghWjdGNhEB5mSi5labAW8pFkqK/IgFCmKbYnMiaX0tPJk3U XV+ZT3zIkIT1E5VqMFcVYjMfx/pb5jdKst+GsXsN7aLej505Zt36D6ssX94zh3cLJS8S/j sbg59VUqL4xvaXuXJ2KPbjPnytxFwJJvH2tLM0GdJgibsP7y7nbtblBFG+0hsA== 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=1739974461; 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=DMEPU0KmasMuOmpm0B0TofD9lwikxK2cj/ZUd2ljEV8=; b=xsoqi4pAjsfmMcCj1HZNRUKQ8GyxGhDp89vJCbZll62Ayqi3N8psTLuxz7eYz4U5PgpPZc FSEp3ysRdQarOq4MkDFCCSN3ooIPR+ZOY350jrOPPKXZVROaVgOWrWEQIn3Yhl5iFqii37 jI2vHt2M8CkeCpfJJK5khfmszB11/B+TWhc8ZtdN7lgXExqqAaGh7gyy89ph2zwIrOsOqS udAdZKOhNxHpLIBgJGK4A7AzQ8fzfjfDXZ8Kc1zOe1o7fMWxqsKjxAlaS6YCaP9F97bd4l lzKuSbj6yIKetImCJdGpl7/fZrP2jimnq86F+3ChyPaIvixN9ZOBHGtt4sLCyg== 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 4YydgK31nVz17Zt; Wed, 19 Feb 2025 14:14:21 +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 51JEELBE038093; Wed, 19 Feb 2025 14:14:21 GMT (envelope-from git@gitrepo.freebsd.org) Received: (from git@localhost) by gitrepo.freebsd.org (8.18.1/8.18.1/Submit) id 51JEELef038090; Wed, 19 Feb 2025 14:14:21 GMT (envelope-from git) Date: Wed, 19 Feb 2025 14:14:21 GMT Message-Id: <202502191414.51JEELef038090@gitrepo.freebsd.org> To: src-committers@FreeBSD.org, dev-commits-src-all@FreeBSD.org, dev-commits-src-main@FreeBSD.org From: Olivier Certner Subject: git: f30309abcce4 - main - vm_phys_add_seg(): Check for bad segments, allow empty ones 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: X-BeenThere: dev-commits-src-all@freebsd.org Sender: owner-dev-commits-src-all@FreeBSD.org MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: 8bit X-Git-Committer: olce X-Git-Repository: src X-Git-Refname: refs/heads/main X-Git-Reftype: branch X-Git-Commit: f30309abcce4cec891413da5cba2db92dd6ab0d7 Auto-Submitted: auto-generated The branch main has been updated by olce: URL: https://cgit.FreeBSD.org/src/commit/?id=f30309abcce4cec891413da5cba2db92dd6ab0d7 commit f30309abcce4cec891413da5cba2db92dd6ab0d7 Author: Olivier Certner AuthorDate: 2024-10-09 17:04:34 +0000 Commit: Olivier Certner CommitDate: 2025-02-19 14:13:26 +0000 vm_phys_add_seg(): Check for bad segments, allow empty ones A bad specification is if 'start' is strictly greater than 'end', or bounds are not page aligned. The latter was already tested under INVARIANTS, but now will be also on production kernels. The reason is that vm_phys_early_startup() pours early segments into the final phys_segs[] array via vm_phys_add_seg(), but vm_phys_early_add_seg() did not check their validity. Checking segments once and for all in vm_phys_add_seg() avoids duplicating validity tests and is possible since early segments are not used before being poured into phys_segs[]. Finally, vm_phys_add_seg() is not performance critical. Allow empty segments and discard them (silently, unless 'bootverbose' is true), as vm_page_startup() was testing for this case before calling vm_phys_add_seg(), and we felt the same test in vm_phys_early_startup() was due before calling vm_phys_add_seg(). As a consequence, remove the empty segment test from vm_page_startup(). Reviewed by: markj MFC after: 1 week Sponsored by: The FreeBSD Foundation Differential Revision: https://reviews.freebsd.org/D48627 --- sys/vm/vm_page.c | 3 +-- sys/vm/vm_phys.c | 16 ++++++++++++---- 2 files changed, 13 insertions(+), 6 deletions(-) diff --git a/sys/vm/vm_page.c b/sys/vm/vm_page.c index f0e3fc73fb34..06965633ee07 100644 --- a/sys/vm/vm_page.c +++ b/sys/vm/vm_page.c @@ -750,8 +750,7 @@ vm_page_startup(vm_offset_t vaddr) * physical pages. */ for (i = 0; phys_avail[i + 1] != 0; i += 2) - if (vm_phys_avail_size(i) != 0) - vm_phys_add_seg(phys_avail[i], phys_avail[i + 1]); + vm_phys_add_seg(phys_avail[i], phys_avail[i + 1]); /* * Initialize the physical memory allocator. diff --git a/sys/vm/vm_phys.c b/sys/vm/vm_phys.c index 01d3d5e22eb0..c28bc5d25616 100644 --- a/sys/vm/vm_phys.c +++ b/sys/vm/vm_phys.c @@ -476,10 +476,18 @@ vm_phys_add_seg(vm_paddr_t start, vm_paddr_t end) { vm_paddr_t paddr; - KASSERT((start & PAGE_MASK) == 0, - ("vm_phys_define_seg: start is not page aligned")); - KASSERT((end & PAGE_MASK) == 0, - ("vm_phys_define_seg: end is not page aligned")); + if ((start & PAGE_MASK) != 0) + panic("%s: start (%jx) is not page aligned", __func__, + (uintmax_t)start); + if ((end & PAGE_MASK) != 0) + panic("%s: end (%jx) is not page aligned", __func__, + (uintmax_t)end); + if (start > end) + panic("%s: start (%jx) > end (%jx)!", __func__, + (uintmax_t)start, (uintmax_t)end); + + if (start == end) + return; /* * Split the physical memory segment if it spans two or more free