From nobody Sat Aug 12 07:56:48 2023 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 4RNCfm6P4Gz4m6p8; Sat, 12 Aug 2023 07:56:48 +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 4RNCfm5mYkz4FqT; Sat, 12 Aug 2023 07:56:48 +0000 (UTC) (envelope-from git@FreeBSD.org) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1691827008; 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=pYSR+Y/JtQ9SQalFtKYH/fKna+EK1oqqqg55yfF9lZE=; b=vl22v8vioh6RdkjXLnScGfQnLjDGNL3Pj3baSWShL66/b/wAJHLYZNKbbO1oOokNA4alHt D9cbAXyiSGRl8XEHVvs/NdhCIyBtI9775ghkJf8u0bPJc37zrX+8MGRRm6Citg/wirPFuk 1NLyv4nLkxOltlit1NysTMLcJx2I8X/yd+7ceknZMN0la5D4iSPBscC3dJhML8pCftS2fu n9KrlqfzmZqrWvJ7Aw8NWHdggFX6cUYHelS45R/7j4bAqi6o5MHhYj+Ay0o6tB1bBSOxIg ZCsBm3SD/USzHpBg0VRhmFqDAkmvC2kfld/7bLhLKY51EVtpbVZcWRr8zCrPYQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1691827008; 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=pYSR+Y/JtQ9SQalFtKYH/fKna+EK1oqqqg55yfF9lZE=; b=QifJEsm+v3oU9mXZMl/1tSA7vBNdYPo3rwgrO2HL2OzF7DSVZkBHOuNH4osCksz4ntFQGf g5VyQ67pbtmPZUhZEweiXjNBxEzdISYdZJVe6uuFqMgqm3qcgUBJXATpK7GnHnDOBSsgmv QSBildqjyuokhKC8GNBvYhKmHp/WgY6DTGkZsY6yRG4ZG2XTMSXV1DF5iqMyBE+aAtU3hL +2o45oj0PNwtul9e/irX08rra16HKtBIgXKTedgZW6duuMa78NGDxv1hGEAtuXk+s/8x/U oR6mWHwKcTS8tyjs4KCQOCabQT2vHHUd3gOOIefsF+41uCejQuIwroNEpmHTIQ== ARC-Seal: i=1; s=dkim; d=freebsd.org; t=1691827008; a=rsa-sha256; cv=none; b=IXmaR8iDLl1rza9sXsMLQFl6OKx1x8OAMD62Hat/BwiM6+U2K9nbKTA+IaGOebaMRBvtwt uW/mfigs+fX1LR8uZID0PwMrN+0xmSRBNK34C87q26tH83m6TGsdMJcG2TQNYjt2G88Aea jxsE6uGEAGZBXihQy8wslZ+Heagkv2Joia3EoRG84k8Bcp21weYshM8dCgdWodiadmZaE9 EHAdl4+AalVqkzaOBtHRv2W4KaJekmvJo2FOB3fDFLSzKKs4d0NLfbYnIHCRU9nykdT6lo n3OP5Iin1AK2x9Zw71tRooGHkK6fFA+tVUhKEmYVTqI+T7cD6uEgD8iJTs6uMg== ARC-Authentication-Results: i=1; mx1.freebsd.org; none 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 4RNCfm4r1mz1C8T; Sat, 12 Aug 2023 07:56:48 +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 37C7um83075087; Sat, 12 Aug 2023 07:56:48 GMT (envelope-from git@gitrepo.freebsd.org) Received: (from git@localhost) by gitrepo.freebsd.org (8.17.1/8.17.1/Submit) id 37C7umYi075084; Sat, 12 Aug 2023 07:56:48 GMT (envelope-from git) Date: Sat, 12 Aug 2023 07:56:48 GMT Message-Id: <202308120756.37C7umYi075084@gitrepo.freebsd.org> To: src-committers@FreeBSD.org, dev-commits-src-all@FreeBSD.org, dev-commits-src-main@FreeBSD.org From: Alan Cox Subject: git: 37e5d49e1e5e - main - vm: Fix address hints of 0 with MAP_32BIT 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: alc X-Git-Repository: src X-Git-Refname: refs/heads/main X-Git-Reftype: branch X-Git-Commit: 37e5d49e1e5e750bf2a200ef2e117d14c4e9a578 Auto-Submitted: auto-generated The branch main has been updated by alc: URL: https://cgit.FreeBSD.org/src/commit/?id=37e5d49e1e5e750bf2a200ef2e117d14c4e9a578 commit 37e5d49e1e5e750bf2a200ef2e117d14c4e9a578 Author: Alan Cox AuthorDate: 2023-08-03 07:07:14 +0000 Commit: Alan Cox CommitDate: 2023-08-12 07:35:21 +0000 vm: Fix address hints of 0 with MAP_32BIT Also, rename min_addr to default_addr, which better reflects what it represents. The min_addr is not a minimum address in the same way that max_addr is actually a maximum address that can be allocated. For example, a non-zero hint can be less than min_addr and be allocated. Reported by: dchagin Reviewed by: dchagin, kib, markj Fixes: d8e6f4946cec0 "vm: Fix anonymous memory clustering under ASLR" Differential Revision: https://reviews.freebsd.org/D41397 --- sys/vm/vm_map.c | 16 ++++++++-------- sys/vm/vm_mmap.c | 14 ++++++++++---- 2 files changed, 18 insertions(+), 12 deletions(-) diff --git a/sys/vm/vm_map.c b/sys/vm/vm_map.c index 8d98af7709cd..c77c00b8b5c6 100644 --- a/sys/vm/vm_map.c +++ b/sys/vm/vm_map.c @@ -2255,19 +2255,19 @@ done: /* * vm_map_find_min() is a variant of vm_map_find() that takes an - * additional parameter (min_addr) and treats the given address - * (*addr) differently. Specifically, it treats *addr as a hint + * additional parameter ("default_addr") and treats the given address + * ("*addr") differently. Specifically, it treats "*addr" as a hint * and not as the minimum address where the mapping is created. * * This function works in two phases. First, it tries to * allocate above the hint. If that fails and the hint is - * greater than min_addr, it performs a second pass, replacing - * the hint with min_addr as the minimum address for the + * greater than "default_addr", it performs a second pass, replacing + * the hint with "default_addr" as the minimum address for the * allocation. */ int vm_map_find_min(vm_map_t map, vm_object_t object, vm_ooffset_t offset, - vm_offset_t *addr, vm_size_t length, vm_offset_t min_addr, + vm_offset_t *addr, vm_size_t length, vm_offset_t default_addr, vm_offset_t max_addr, int find_space, vm_prot_t prot, vm_prot_t max, int cow) { @@ -2277,14 +2277,14 @@ vm_map_find_min(vm_map_t map, vm_object_t object, vm_ooffset_t offset, hint = *addr; if (hint == 0) { cow |= MAP_NO_HINT; - *addr = hint = min_addr; + *addr = hint = default_addr; } for (;;) { rv = vm_map_find(map, object, offset, addr, length, max_addr, find_space, prot, max, cow); - if (rv == KERN_SUCCESS || min_addr >= hint) + if (rv == KERN_SUCCESS || default_addr >= hint) return (rv); - *addr = hint = min_addr; + *addr = hint = default_addr; } } diff --git a/sys/vm/vm_mmap.c b/sys/vm/vm_mmap.c index 7876a055ca91..d904c4f38e40 100644 --- a/sys/vm/vm_mmap.c +++ b/sys/vm/vm_mmap.c @@ -1555,7 +1555,7 @@ vm_mmap_object(vm_map_t map, vm_offset_t *addr, vm_size_t size, vm_prot_t prot, vm_prot_t maxprot, int flags, vm_object_t object, vm_ooffset_t foff, boolean_t writecounted, struct thread *td) { - vm_offset_t max_addr; + vm_offset_t default_addr, max_addr; int docow, error, findspace, rv; bool curmap, fitit; @@ -1630,10 +1630,16 @@ vm_mmap_object(vm_map_t map, vm_offset_t *addr, vm_size_t size, vm_prot_t prot, max_addr = MAP_32BIT_MAX_ADDR; #endif if (curmap) { - rv = vm_map_find_min(map, object, foff, addr, size, + default_addr = round_page((vm_offset_t)td->td_proc->p_vmspace-> - vm_daddr + lim_max(td, RLIMIT_DATA)), max_addr, - findspace, prot, maxprot, docow); + vm_daddr + lim_max(td, RLIMIT_DATA)); +#ifdef MAP_32BIT + if ((flags & MAP_32BIT) != 0) + default_addr = 0; +#endif + rv = vm_map_find_min(map, object, foff, addr, size, + default_addr, max_addr, findspace, prot, maxprot, + docow); } else { rv = vm_map_find(map, object, foff, addr, size, max_addr, findspace, prot, maxprot, docow);