From nobody Sat May 28 17:53:38 2022 X-Original-To: dev-commits-src-main@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 43D3B1B457D9; Sat, 28 May 2022 17:53:39 +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 4L9Tmy6ttnz3vhR; Sat, 28 May 2022 17:53:38 +0000 (UTC) (envelope-from git@FreeBSD.org) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1653760419; 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=yG78fs2/z4lU5RZy1/dTDFy5Cb+ea5Vqeo30SdHMCdY=; b=fFA4A7Qc8SO7KXfkDemG5lEKCrpeUqXez8n7lTITENBOqK72tt/WVoH5GsIHC3NHAXsuGJ ufzw+Xo96Uw2ze6/wKvO1z0iyXej+w/NnPhZRrNdjDETZj8kTrWXh5WumbiEfEUuXrtp10 DUmoG1fk2aRzBPaDdl/RPkekxsD53Xm8TmLqVvlioxMWqUHEq34ttCEhOYSAM0KbQIcskC xrlESb3//pD2s3S3/Q+HU+DJeOKxomsYT6De3Sht0rop+Zy6ysyisbLF3PkySIbuDVBenk 28IYj3JeLOCvRE17cV7OhHo5xIyscb2D7UvzwifcK0bpWS8PAvRnngEJ3Sbebw== 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 C3DE2134D4; Sat, 28 May 2022 17:53:38 +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 24SHrch6057252; Sat, 28 May 2022 17:53:38 GMT (envelope-from git@gitrepo.freebsd.org) Received: (from git@localhost) by gitrepo.freebsd.org (8.16.1/8.16.1/Submit) id 24SHrcFa057251; Sat, 28 May 2022 17:53:38 GMT (envelope-from git) Date: Sat, 28 May 2022 17:53:38 GMT Message-Id: <202205281753.24SHrcFa057251@gitrepo.freebsd.org> To: src-committers@FreeBSD.org, dev-commits-src-all@FreeBSD.org, dev-commits-src-main@FreeBSD.org From: Dmitry Chagin Subject: git: d46174cd8838 - main - Finish cpuset_getaffinity() after f35093f8 List-Id: Commit messages for the main branch of the src repository List-Archive: https://lists.freebsd.org/archives/dev-commits-src-main List-Help: List-Post: List-Subscribe: List-Unsubscribe: Sender: owner-dev-commits-src-main@freebsd.org X-BeenThere: dev-commits-src-main@freebsd.org MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: 8bit X-Git-Committer: dchagin X-Git-Repository: src X-Git-Refname: refs/heads/main X-Git-Reftype: branch X-Git-Commit: d46174cd8838b86b9fe956b80c82bd238c302b2e Auto-Submitted: auto-generated ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1653760419; 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=yG78fs2/z4lU5RZy1/dTDFy5Cb+ea5Vqeo30SdHMCdY=; b=yI6VD5Iss+z/7DmhI0uI1+tppo6WDTS5v7NvCCwDTdirMRsIyBBsTmka1oRvJonV6+6Fkh HDEQ1S+BA7wYo4laK7g9fI9/e13TWx9nRjd19usmQHlctdI2q6yLxh71fjJbxikljMiHJx sYn6RcW6BsEooJL9y/Adaz33Sp0wsvpLF7fc1Ml2eXCtqdD2mLtBaz00Kj9gCIn7WEThL9 07sUwNaU6DBOVUu7R+DYLZUd4rttcKVueq410hH5ftKNeib8kTjbEX9wAOThDVVUZXIe67 c2bFYwVohxP8gudYQbNpFhFZh5ALdzFCEErnphjcUh6X0oyHmmEo0Sg0dknzVw== ARC-Seal: i=1; s=dkim; d=freebsd.org; t=1653760419; a=rsa-sha256; cv=none; b=ZFGkOB5rLz7J9MIZs5Y2oky81ARFWI+L+QVG6mzNTCQOXUloChFMcri7Z+7JQ8fsZ4YiGB keUc5TjMT9g9EO/uQ6TumNcUssWYVoyeadK94KLV7EhfuXGdq1W5LQbPy+N+8XTPvplCry JJXV1YXp3vI75b+U3VHThRHWJ5kCrxC+uJIT9Wmp1GntqgO9f1lHPpK4GPvUQ2H7Wv2i54 sSj8tLdnp/KgKxyTd99TNQ2HpDPK3eCyAgYJg9hoIEO9mL2xcdMx/vrZ2CUr5qowm/Zi1X gbXBnAwXQFuHNVA4vfFMgs8HXKoCBJgmFr624dkxCU1sqnntFRETBp8y5VJBsA== ARC-Authentication-Results: i=1; mx1.freebsd.org; none X-ThisMailContainsUnwantedMimeParts: N The branch main has been updated by dchagin: URL: https://cgit.FreeBSD.org/src/commit/?id=d46174cd8838b86b9fe956b80c82bd238c302b2e commit d46174cd8838b86b9fe956b80c82bd238c302b2e Author: Dmitry Chagin AuthorDate: 2022-05-28 17:53:08 +0000 Commit: Dmitry Chagin CommitDate: 2022-05-28 17:53:08 +0000 Finish cpuset_getaffinity() after f35093f8 Split cpuset_getaffinity() into a two counterparts, where the user_cpuset_getaffinity() is intended to operate on the cpuset_t from user va, while kern_cpuset_getaffinity() expects the cpuset from kernel va. Accordingly, the code that clears the high bits is moved to the user_cpuset_getaffinity(). Linux sched_getaffinity() syscall returns the size of set copied to the user-space and then glibc wrapper clears the high bits. MFC after: 2 weeks --- sys/compat/freebsd32/freebsd32_misc.c | 2 +- sys/compat/linux/linux_misc.c | 17 ++++++------- sys/kern/kern_cpuset.c | 45 +++++++++++++++++++++-------------- sys/sys/syscallsubr.h | 4 +++- 4 files changed, 40 insertions(+), 28 deletions(-) diff --git a/sys/compat/freebsd32/freebsd32_misc.c b/sys/compat/freebsd32/freebsd32_misc.c index 46e4ffb39525..67dcaa35cae5 100644 --- a/sys/compat/freebsd32/freebsd32_misc.c +++ b/sys/compat/freebsd32/freebsd32_misc.c @@ -3373,7 +3373,7 @@ freebsd32_cpuset_getaffinity(struct thread *td, struct freebsd32_cpuset_getaffinity_args *uap) { - return (kern_cpuset_getaffinity(td, uap->level, uap->which, + return (user_cpuset_getaffinity(td, uap->level, uap->which, PAIR32TO64(id_t,uap->id), uap->cpusetsize, uap->mask, &cpuset_copy32_cb)); } diff --git a/sys/compat/linux/linux_misc.c b/sys/compat/linux/linux_misc.c index 225187826677..3321c9cdd98a 100644 --- a/sys/compat/linux/linux_misc.c +++ b/sys/compat/linux/linux_misc.c @@ -2241,11 +2241,6 @@ linux_sched_getparam(struct thread *td, return (error); } -static const struct cpuset_copy_cb copy_set = { - .cpuset_copyin = copyin, - .cpuset_copyout = copyout -}; - /* * Get affinity of a process. */ @@ -2254,6 +2249,8 @@ linux_sched_getaffinity(struct thread *td, struct linux_sched_getaffinity_args *args) { struct thread *tdt; + cpuset_t *mask; + size_t size; int error; id_t tid; @@ -2263,13 +2260,17 @@ linux_sched_getaffinity(struct thread *td, tid = tdt->td_tid; PROC_UNLOCK(tdt->td_proc); + mask = malloc(sizeof(cpuset_t), M_LINUX, M_WAITOK | M_ZERO); + size = min(args->len, sizeof(cpuset_t)); error = kern_cpuset_getaffinity(td, CPU_LEVEL_WHICH, CPU_WHICH_TID, - tid, args->len, (cpuset_t *)args->user_mask_ptr, ©_set); + tid, size, mask); if (error == ERANGE) error = EINVAL; + if (error == 0) + error = copyout(mask, args->user_mask_ptr, size); if (error == 0) - td->td_retval[0] = min(args->len, sizeof(cpuset_t)); - + td->td_retval[0] = size; + free(mask, M_LINUX); return (error); } diff --git a/sys/kern/kern_cpuset.c b/sys/kern/kern_cpuset.c index a5c644687241..0670d9a046a7 100644 --- a/sys/kern/kern_cpuset.c +++ b/sys/kern/kern_cpuset.c @@ -1888,29 +1888,26 @@ int sys_cpuset_getaffinity(struct thread *td, struct cpuset_getaffinity_args *uap) { - return (kern_cpuset_getaffinity(td, uap->level, uap->which, + return (user_cpuset_getaffinity(td, uap->level, uap->which, uap->id, uap->cpusetsize, uap->mask, ©_set)); } int kern_cpuset_getaffinity(struct thread *td, cpulevel_t level, cpuwhich_t which, - id_t id, size_t cpusetsize, cpuset_t *maskp, const struct cpuset_copy_cb *cb) + id_t id, size_t cpusetsize, cpuset_t *mask) { struct thread *ttd; struct cpuset *nset; struct cpuset *set; struct proc *p; - cpuset_t *mask; int error; - size_t size; error = cpuset_check_capabilities(td, level, which, id); if (error != 0) return (error); - mask = malloc(sizeof(cpuset_t), M_TEMP, M_WAITOK | M_ZERO); error = cpuset_which(which, id, &p, &ttd, &set); - if (error) - goto out; + if (error != 0) + return (error); switch (level) { case CPU_LEVEL_ROOT: case CPU_LEVEL_CPUSET: @@ -1928,8 +1925,7 @@ kern_cpuset_getaffinity(struct thread *td, cpulevel_t level, cpuwhich_t which, case CPU_WHICH_INTRHANDLER: case CPU_WHICH_ITHREAD: case CPU_WHICH_DOMAIN: - error = EINVAL; - goto out; + return (EINVAL); } if (level == CPU_LEVEL_ROOT) nset = cpuset_refroot(set); @@ -1978,11 +1974,28 @@ kern_cpuset_getaffinity(struct thread *td, cpulevel_t level, cpuwhich_t which, if (p) PROC_UNLOCK(p); if (error == 0) { - if (cpusetsize < howmany(CPU_FLS(mask), NBBY)) { - error = ERANGE; - goto out; - } - size = min(cpusetsize, sizeof(cpuset_t)); + if (cpusetsize < howmany(CPU_FLS(mask), NBBY)) + return (ERANGE); +#ifdef KTRACE + if (KTRPOINT(td, KTR_STRUCT)) + ktrcpuset(mask, cpusetsize); +#endif + } + return (error); +} + +int +user_cpuset_getaffinity(struct thread *td, cpulevel_t level, cpuwhich_t which, + id_t id, size_t cpusetsize, cpuset_t *maskp, const struct cpuset_copy_cb *cb) +{ + cpuset_t *mask; + size_t size; + int error; + + mask = malloc(sizeof(cpuset_t), M_TEMP, M_WAITOK | M_ZERO); + size = min(cpusetsize, sizeof(cpuset_t)); + error = kern_cpuset_getaffinity(td, level, which, id, size, mask); + if (error == 0) { error = cb->cpuset_copyout(mask, maskp, size); if (error != 0) goto out; @@ -2003,10 +2016,6 @@ kern_cpuset_getaffinity(struct thread *td, cpulevel_t level, cpuwhich_t which, cp++; } } -#ifdef KTRACE - if ( KTRPOINT(td, KTR_STRUCT)) - ktrcpuset(mask, size); -#endif } out: free(mask, M_TEMP); diff --git a/sys/sys/syscallsubr.h b/sys/sys/syscallsubr.h index 70e33e9244c4..5520d1ea8f89 100644 --- a/sys/sys/syscallsubr.h +++ b/sys/sys/syscallsubr.h @@ -119,9 +119,11 @@ int kern_connectat(struct thread *td, int dirfd, int fd, struct sockaddr *sa); int kern_copy_file_range(struct thread *td, int infd, off_t *inoffp, int outfd, off_t *outoffp, size_t len, unsigned int flags); -int kern_cpuset_getaffinity(struct thread *td, cpulevel_t level, +int user_cpuset_getaffinity(struct thread *td, cpulevel_t level, cpuwhich_t which, id_t id, size_t cpusetsize, cpuset_t *maskp, const struct cpuset_copy_cb *cb); +int kern_cpuset_getaffinity(struct thread *td, cpulevel_t level, + cpuwhich_t which, id_t id, size_t cpusetsize, cpuset_t *mask); int kern_cpuset_setaffinity(struct thread *td, cpulevel_t level, cpuwhich_t which, id_t id, cpuset_t *maskp); int user_cpuset_setaffinity(struct thread *td, cpulevel_t level,