From nobody Tue Jan 18 18:49:20 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 DF2711975842; Tue, 18 Jan 2022 18:49:20 +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 4Jdd9D5Xmbz4Xpj; Tue, 18 Jan 2022 18:49:20 +0000 (UTC) (envelope-from git@FreeBSD.org) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1642531760; 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=PLNHtB4EISjSl4/+nMTUmVcknHJQdRUESK5y8TX3nJc=; b=EUtpGwnOrZIunmH3AuD/tlEI/cHnFUCk7A64P7rCeyaqhtXBXLaYlMRHfRNV+hky6hmagA GeYzKLFLy/5d7X1EzluTBfvaGLW+oUMG71Rn4faDgO0Vk81ERXeOdry7GzcZYm4+HKcjRv saVXfBlLKQDzGWX0C/wyAmvJcIntXKZ6ptTQCuocX8A8V4qrD0UwWz1z+KC1T8PeYgVttw 68JnIFryr0bel8jG/m2772ZlafbHMSkYxBkXzfCIlRfaBJax1jYlQNNGY4w4G75uxKO+5T ENnshJ2uz3Qb2UM9ipIEDVmHIrcFf5XFRxEELxu9vj7rGP5N0O3gkjgJWFg44A== 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 9EA81263B3; Tue, 18 Jan 2022 18:49:20 +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 20IInKEf031946; Tue, 18 Jan 2022 18:49:20 GMT (envelope-from git@gitrepo.freebsd.org) Received: (from git@localhost) by gitrepo.freebsd.org (8.16.1/8.16.1/Submit) id 20IInKlP031945; Tue, 18 Jan 2022 18:49:20 GMT (envelope-from git) Date: Tue, 18 Jan 2022 18:49:20 GMT Message-Id: <202201181849.20IInKlP031945@gitrepo.freebsd.org> To: src-committers@FreeBSD.org, dev-commits-src-all@FreeBSD.org, dev-commits-src-main@FreeBSD.org From: Doug Moore Subject: git: da92ecbc0d8f - main - vm_phys: fix seg->end test in alloc_seg_contig 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: dougm X-Git-Repository: src X-Git-Refname: refs/heads/main X-Git-Reftype: branch X-Git-Commit: da92ecbc0d8f4652cd5c97aace290103055c7019 Auto-Submitted: auto-generated ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1642531760; 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=PLNHtB4EISjSl4/+nMTUmVcknHJQdRUESK5y8TX3nJc=; b=yg6GN9siJVUk+/8AOjUu/fCNZPCh57+lxyCVr9z1zayrjL3Va7y9bow1F2WGjmD/83Ztw4 fmiSdoW+b849iYOznDaYlCftVmEGv0Sb3B5GmMIZNHZKraCiud/3HmLkMNV0K3rtk3fNwN 6t519DTeaBcCCDmp32tAEJe1y7aDFIEEnsLNyrIJ8tGxC6mI/DMn3EpYBnJvyi0aDV5QzE lkf/rHSd/A5qnYZKKCibvWtyV4uhvdHT2DcfyDaX8drIV6p7XnWYbD6w7072Lu2rpe96tF BvzPb+sjX39ZTPxVQVhZltsnXuCkr2oTZUBweg16p/r9YqtWi9AqHTdYnK88SA== ARC-Seal: i=1; s=dkim; d=freebsd.org; t=1642531760; a=rsa-sha256; cv=none; b=JDZ4huUMkWKWCjpfjB1n3dSflit1e9z4Iy0wu2RiT42Mnx2za8KdWSURpc4B9iQ95BxS7k kNYR1Isz5NFjm+WRMC8sHHedKIQQRbnKklJxxYHNNRN9Wjd+YKAMy36ckV9mdKZ1rrhBnh 5AQxIynwA8T6nuyQYY/i1MMfW5uQMignEOlAYDIMO5j7B1h+KGmcEcwrQ+iIG5KKbcLXIz ALNsldhi8TwOqG3aJl+eG0Qg+H4E5HFWy0sz1coMgKyYImY5X5w0WK51Oyjh4cHzoOaN7O jIpHXouZTQX+gu1hAq9P4GKofWKPmmuFiMKB2TROCiN5wKfjt8FvY/lrZ4Mc7g== ARC-Authentication-Results: i=1; mx1.freebsd.org; none X-ThisMailContainsUnwantedMimeParts: N The branch main has been updated by dougm: URL: https://cgit.FreeBSD.org/src/commit/?id=da92ecbc0d8f4652cd5c97aace290103055c7019 commit da92ecbc0d8f4652cd5c97aace290103055c7019 Author: Doug Moore AuthorDate: 2022-01-18 18:32:46 +0000 Commit: Doug Moore CommitDate: 2022-01-18 18:49:09 +0000 vm_phys: fix seg->end test in alloc_seg_contig In vm_phys_alloc_seg_contig, in allocating multiple memory blocks for a huge allocation, ensure that the end of the allocated range does not exceed the upper segment limit. Reorder a couple of checks to improve code layout. Reviewed by: alc MFC after: 1 week Differential Revision: https://reviews.freebsd.org/D33870 --- sys/vm/vm_phys.c | 69 +++++++++++++++++++++++++++----------------------------- 1 file changed, 33 insertions(+), 36 deletions(-) diff --git a/sys/vm/vm_phys.c b/sys/vm/vm_phys.c index 6798c55cc91c..a880b7abd324 100644 --- a/sys/vm/vm_phys.c +++ b/sys/vm/vm_phys.c @@ -1428,47 +1428,44 @@ vm_phys_alloc_seg_contig(struct vm_phys_seg *seg, u_long npages, fl = (*seg->free_queues)[pind]; TAILQ_FOREACH(m_ret, &fl[oind].pl, listq) { /* - * Is the size of this allocation request - * larger than the largest block size? + * Determine if the address range starting at pa + * is within the given range, satisfies the + * given alignment, and does not cross the given + * boundary. */ - if (order >= VM_NFREEORDER) { - /* - * Determine if a sufficient number of - * subsequent blocks to satisfy the - * allocation request are free. - */ - pa = VM_PAGE_TO_PHYS(m_ret); - pa_end = pa + size; - if (pa_end < pa) - continue; - for (;;) { - pa += 1 << (PAGE_SHIFT + - VM_NFREEORDER - 1); - if (pa >= pa_end || - pa < seg->start || - pa >= seg->end) - break; - m = &seg->first_page[atop(pa - - seg->start)]; - if (m->order != VM_NFREEORDER - - 1) - break; - } - /* If not, go to the next block. */ - if (pa < pa_end) - continue; - } + pa = VM_PAGE_TO_PHYS(m_ret); + pa_end = pa + size; + if (pa < low || pa_end > high || + !vm_addr_ok(pa, size, alignment, boundary)) + continue; /* - * Determine if the blocks are within the - * given range, satisfy the given alignment, - * and do not cross the given boundary. + * Is the size of this allocation request + * no more than the largest block size? */ - pa = VM_PAGE_TO_PHYS(m_ret); - pa_end = pa + size; - if (pa >= low && pa_end <= high && - vm_addr_ok(pa, size, alignment, boundary)) + if (order < VM_NFREEORDER) goto done; + + /* + * Determine if the address range is valid + * (without overflow in pa_end calculation) + * and fits within the segment. + */ + if (pa_end < pa || pa_end > seg->end) + continue; + + /* + * Determine if a sufficient number of + * subsequent blocks to satisfy the + * allocation request are free. + */ + do { + pa += 1 << + (PAGE_SHIFT + VM_NFREEORDER - 1); + if (pa >= pa_end) + goto done; + } while (VM_NFREEORDER - 1 == seg->first_page[ + atop(pa - seg->start)].order); } } }