From nobody Thu Dec 21 18:17:46 2023 X-Original-To: dev-commits-src-branches@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 4SwzDp6ccYz554s5; Thu, 21 Dec 2023 18:17:46 +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 4SwzDp51myz3Y0Z; Thu, 21 Dec 2023 18:17:46 +0000 (UTC) (envelope-from git@FreeBSD.org) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1703182666; 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=Hw2pCaq1JgPRImFfwnsEWbQN7kzpjlSYNwZdbV8QTJ0=; b=VJjxWjQZdm2UiQNQG1Rv4g1loqrV51JT8Rs82nfvFIOrHdYmkTFYckojI0E7nAVy7NLDbt M1TYmKGrQXTdUAnb8BtPFULF/MwZVko0FJ/fzawOX4HEmnxhV7sBzTlkAo9LDI7NvUIeRx vvzvIwepHrh/1tjbM5ppyJxDykfWMmA/h4zCCb0/kpkr4XebEvT8UZbcbZScNcIC+tRWzY Lb1X6t6jJecloud0lGvDYAOBsUffODiPbENT0Qa2q6rQmB1tDXZ3F78m5ZPH2MMi+ym6LC iVTrR4CRhqBnszOpm2MUXb/Nl+FEVpH3/F0o6UeJJlckEa/QDmmslZhiX6x3tA== ARC-Seal: i=1; s=dkim; d=freebsd.org; t=1703182666; a=rsa-sha256; cv=none; b=aao3iH+n0N3Bv95jNYqWpcTEPahfKQjo1V5kR6Qn4dBWW3fnE9asGZ9Ptz2H9w8pf6vaBl 00UY86E/Z6xmKC4ARlgmqyOwyvE8yaVO5kK8nPgpy/8RDKaAWKa0lgSVsuBCYCRiEZvj5e Nm2lYQ+uqQ0Lr2HIk1WSRHPqjOS4PX6TPqX/hiZ4VOkMHxU67oVIieVNMUkD3dwD2w8adl +1Yl/f5UA5u2ZVtEWTBJpVrcCeo9POuVstrtS8/mgK1GGx+jgfA6GoIfJ966OfmNGfMk4x ye9lrRstOrzvu2p31f4DpSbIgxHTOvd/rHHpOjc1KccEbIwQUzEU3QXx0N/mhw== 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=1703182666; 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=Hw2pCaq1JgPRImFfwnsEWbQN7kzpjlSYNwZdbV8QTJ0=; b=WALKJmrQpI3bR/ZseBty/EmA2VUkD1e9Fd8LtSgJEbi8mYeyQSfqJEAAWLcw4ay/Z96B2B Ia9dck1VgsHRPbSvsxoSZA6cIWV5C8SoW3MZb1xDCYSzc+pTlFoI7ahpOFhoMxQY4Nc+Ud Gs8/gEeQtpPlrj0JlT1Openp6i0iibQOIGkOMJeBYh071DaJ2yH92KgGSiuS2Fzbhl3Qm6 oVpgpzILvIp/9cBpOHEbiVT0YgcotGMbZSJrC7D9wvYAwMO0cjT8pU82gSbN+BUQCq72Sl 0a98SyJdh0D1+Cf1RFkdpHyS6uKCaz40GAkgGM2Uj9zj6azV6Del1Z4FZFsdzw== 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 4SwzDp3nvqzjfC; Thu, 21 Dec 2023 18:17:46 +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 3BLIHkxj034127; Thu, 21 Dec 2023 18:17:46 GMT (envelope-from git@gitrepo.freebsd.org) Received: (from git@localhost) by gitrepo.freebsd.org (8.17.1/8.17.1/Submit) id 3BLIHklI034124; Thu, 21 Dec 2023 18:17:46 GMT (envelope-from git) Date: Thu, 21 Dec 2023 18:17:46 GMT Message-Id: <202312211817.3BLIHklI034124@gitrepo.freebsd.org> To: src-committers@FreeBSD.org, dev-commits-src-all@FreeBSD.org, dev-commits-src-branches@FreeBSD.org From: Brooks Davis Subject: git: c6e072f15c98 - stable/14 - memfd_create: don't allocate heap memory List-Id: Commits to the stable branches of the FreeBSD src repository List-Archive: https://lists.freebsd.org/archives/dev-commits-src-branches List-Help: List-Post: List-Subscribe: List-Unsubscribe: Sender: owner-dev-commits-src-branches@freebsd.org X-BeenThere: dev-commits-src-branches@freebsd.org MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: 8bit X-Git-Committer: brooks X-Git-Repository: src X-Git-Refname: refs/heads/stable/14 X-Git-Reftype: branch X-Git-Commit: c6e072f15c98097bdfb9583345f910220f97093e Auto-Submitted: auto-generated The branch stable/14 has been updated by brooks: URL: https://cgit.FreeBSD.org/src/commit/?id=c6e072f15c98097bdfb9583345f910220f97093e commit c6e072f15c98097bdfb9583345f910220f97093e Author: Brooks Davis AuthorDate: 2023-11-27 17:07:06 +0000 Commit: Brooks Davis CommitDate: 2023-12-21 18:13:19 +0000 memfd_create: don't allocate heap memory Rather than calling calloc() to allocate space for a page size array to pass to getpagesizes(), just follow the getpagesizes() implementation and allocate MAXPAGESIZES elements on the stack. This avoids the need for the allocation. While this does mean that a new libc is required to take advantage of a new huge page size, that was already true due to getpagesizes() using a static buffer of MAXPAGESIZES elements. Reviewed by: kevans, imp, emaste Sponsored by: DARPA Differential Revision: https://reviews.freebsd.org/D42710 (cherry picked from commit c96772227b7dfcaf4eec4d07acb5c916643aca3a) --- lib/libc/gen/memfd_create.c | 16 +++------------- 1 file changed, 3 insertions(+), 13 deletions(-) diff --git a/lib/libc/gen/memfd_create.c b/lib/libc/gen/memfd_create.c index b26d638656a4..78131f46d7b1 100644 --- a/lib/libc/gen/memfd_create.c +++ b/lib/libc/gen/memfd_create.c @@ -35,7 +35,6 @@ #include #include #include -#include #include #include @@ -52,7 +51,8 @@ int memfd_create(const char *name, unsigned int flags) { char memfd_name[NAME_MAX + 1]; - size_t namelen, *pgs, pgsize; + size_t pgs[MAXPAGESIZES]; + size_t namelen, pgsize; struct shm_largepage_conf slc; int error, fd, npgs, oflags, pgidx, saved_errno, shmflags; @@ -92,16 +92,9 @@ memfd_create(const char *name, unsigned int flags) if (fd == -1 || (flags & MFD_HUGETLB) == 0) return (fd); - pgs = NULL; - npgs = getpagesizes(NULL, 0); + npgs = getpagesizes(pgs, nitems(pgs)); if (npgs == -1) goto clean; - pgs = calloc(npgs, sizeof(size_t)); - if (pgs == NULL) - goto clean; - error = getpagesizes(pgs, npgs); - if (error == -1) - goto clean; pgsize = (size_t)1 << ((flags & MFD_HUGE_MASK) >> MFD_HUGE_SHIFT); for (pgidx = 0; pgidx < npgs; pgidx++) { if (pgsize == pgs[pgidx]) @@ -111,8 +104,6 @@ memfd_create(const char *name, unsigned int flags) errno = EOPNOTSUPP; goto clean; } - free(pgs); - pgs = NULL; memset(&slc, 0, sizeof(slc)); slc.psind = pgidx; @@ -125,7 +116,6 @@ memfd_create(const char *name, unsigned int flags) clean: saved_errno = errno; close(fd); - free(pgs); errno = saved_errno; return (-1); }