From owner-svn-src-head@freebsd.org Wed Nov 25 01:42:33 2020 Return-Path: Delivered-To: svn-src-head@mailman.nyi.freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2610:1c1:1:606c::19:1]) by mailman.nyi.freebsd.org (Postfix) with ESMTP id 62B83470AE0; Wed, 25 Nov 2020 01:42:33 +0000 (UTC) (envelope-from kevans@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 "Let's Encrypt Authority X3" (verified OK)) by mx1.freebsd.org (Postfix) with ESMTPS id 4CgkCs2LJdz3qsP; Wed, 25 Nov 2020 01:42:33 +0000 (UTC) (envelope-from kevans@FreeBSD.org) Received: from repo.freebsd.org (repo.freebsd.org [IPv6:2610:1c1:1:6068::e6a:0]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (Client did not present a certificate) by mxrelay.nyi.freebsd.org (Postfix) with ESMTPS id 43359E5D; Wed, 25 Nov 2020 01:42:33 +0000 (UTC) (envelope-from kevans@FreeBSD.org) Received: from repo.freebsd.org ([127.0.1.37]) by repo.freebsd.org (8.15.2/8.15.2) with ESMTP id 0AP1gXXM020739; Wed, 25 Nov 2020 01:42:33 GMT (envelope-from kevans@FreeBSD.org) Received: (from kevans@localhost) by repo.freebsd.org (8.15.2/8.15.2/Submit) id 0AP1gXav020738; Wed, 25 Nov 2020 01:42:33 GMT (envelope-from kevans@FreeBSD.org) Message-Id: <202011250142.0AP1gXav020738@repo.freebsd.org> X-Authentication-Warning: repo.freebsd.org: kevans set sender to kevans@FreeBSD.org using -f From: Kyle Evans Date: Wed, 25 Nov 2020 01:42:33 +0000 (UTC) To: src-committers@freebsd.org, svn-src-all@freebsd.org, svn-src-head@freebsd.org Subject: svn commit: r368009 - head/sys/kern X-SVN-Group: head X-SVN-Commit-Author: kevans X-SVN-Commit-Paths: head/sys/kern X-SVN-Commit-Revision: 368009 X-SVN-Commit-Repository: base MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit X-BeenThere: svn-src-head@freebsd.org X-Mailman-Version: 2.1.34 Precedence: list List-Id: SVN commit messages for the src tree for head/-current List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Wed, 25 Nov 2020 01:42:33 -0000 Author: kevans Date: Wed Nov 25 01:42:32 2020 New Revision: 368009 URL: https://svnweb.freebsd.org/changeset/base/368009 Log: kern: cpuset: allow cpuset_create() to take an allocated *setp Currently, it must always allocate a new set to be used for passing to _cpuset_create, but it doesn't have to. This is purely kern_cpuset.c internal and it's sparsely used, so just change it to use *setp if it's not-NULL and modify the two consumers to pass in the address of a NULL cpuset. This paves the way for consumers that want the unr allocation without the possibility of sleeping as long as they've done their due diligence to ensure that the mask will properly apply atop the supplied parent (i.e. avoiding the free_unr() in the last failure path). Reviewed by: jamie, markj MFC after: 1 week Differential Revision: https://reviews.freebsd.org/D27297 Modified: head/sys/kern/kern_cpuset.c Modified: head/sys/kern/kern_cpuset.c ============================================================================== --- head/sys/kern/kern_cpuset.c Wed Nov 25 01:31:00 2020 (r368008) +++ head/sys/kern/kern_cpuset.c Wed Nov 25 01:42:32 2020 (r368009) @@ -326,6 +326,10 @@ _cpuset_create(struct cpuset *set, struct cpuset *pare * Create a new non-anonymous set with the requested parent and mask. May * return failures if the mask is invalid or a new number can not be * allocated. + * + * If *setp is not NULL, then it will be used as-is. The caller must take + * into account that *setp will be inserted at the head of cpuset_ids and + * plan any potentially conflicting cs_link usage accordingly. */ static int cpuset_create(struct cpuset **setp, struct cpuset *parent, const cpuset_t *mask) @@ -333,16 +337,22 @@ cpuset_create(struct cpuset **setp, struct cpuset *par struct cpuset *set; cpusetid_t id; int error; + bool dofree; id = alloc_unr(cpuset_unr); if (id == -1) return (ENFILE); - *setp = set = uma_zalloc(cpuset_zone, M_WAITOK | M_ZERO); + dofree = (*setp == NULL); + if (*setp != NULL) + set = *setp; + else + *setp = set = uma_zalloc(cpuset_zone, M_WAITOK | M_ZERO); error = _cpuset_create(set, parent, mask, NULL, id); if (error == 0) return (0); free_unr(cpuset_unr, id); - uma_zfree(cpuset_zone, set); + if (dofree) + uma_zfree(cpuset_zone, set); return (error); } @@ -1552,16 +1562,17 @@ cpuset_create_root(struct prison *pr, struct cpuset ** KASSERT(pr != NULL, ("[%s:%d] invalid pr", __func__, __LINE__)); KASSERT(setp != NULL, ("[%s:%d] invalid setp", __func__, __LINE__)); - error = cpuset_create(setp, pr->pr_cpuset, &pr->pr_cpuset->cs_mask); + set = NULL; + error = cpuset_create(&set, pr->pr_cpuset, &pr->pr_cpuset->cs_mask); if (error) return (error); - KASSERT(*setp != NULL, ("[%s:%d] cpuset_create returned invalid data", + KASSERT(set != NULL, ("[%s:%d] cpuset_create returned invalid data", __func__, __LINE__)); /* Mark the set as root. */ - set = *setp; set->cs_flags |= CPU_SET_ROOT; + *setp = set; return (0); } @@ -1618,6 +1629,7 @@ sys_cpuset(struct thread *td, struct cpuset_args *uap) thread_lock(td); root = cpuset_refroot(td->td_cpuset); thread_unlock(td); + set = NULL; error = cpuset_create(&set, root, &root->cs_mask); cpuset_rel(root); if (error)