From nobody Mon Feb 06 19:07:44 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 4P9bPD6r1Hz3n4QD; Mon, 6 Feb 2023 19:07:44 +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 4P9bPD6GkDz3Pvp; Mon, 6 Feb 2023 19:07:44 +0000 (UTC) (envelope-from git@FreeBSD.org) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1675710464; 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=1AjxQd6Rbg+Sm8j0BjelFGx2/KffhW4LdlnL+wZE4uQ=; b=Cbl91v1ZJiq2NT9rJAoQPeKBDpWm4zsHQdj1/iPtVCq82iYHMCRAw1gLecoMUtjuXDuQM/ FCeT4yllx7b27npMV3NaTwKpzg2hEOx4S57KTTXUzz8RYbzMiBPQeraPAkZF4VUO/59Nmu A85SNnc/0c2hWF58wX6R9yB3Tw6Q9mAYxr5zAyaGJI6jo1W63i52XkP69F/sSJzFVhaypw fUWQnJtCxLVgTuqhQzGOc/s9FazZP9wniy9aTvGjHjDKVdITlIyko+yBMT2yUY/HKX6LcB xzSEHcbYSPa1ro2xzOh+XEL2EPTyWpBWxV7b6pjXV5e2/fkrRDOHB5WTQ+xkfg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1675710464; 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=1AjxQd6Rbg+Sm8j0BjelFGx2/KffhW4LdlnL+wZE4uQ=; b=BT5SFynr3KWIv8IuJMK0AI0pVFG+gV2ZBR/yUb/KQy1MJdfcTJ8G3xPVlgepmvspnB5xmu npwDv0hk9xHpu2L6fOTWzPCHIAeC6qIBL8i94dSzmYcG7dIixMP6HL/6IH7JzG3UYBe22L X/oSqHbft37JoS6ULlU3nztQCgzeawD6ky83RuQy6MZzcPyzq3TnPqm/0vVerfZVjxGMqY q0QkBmaQthlJIjrpOdt5IMuKUyDH2rau9KaSShh1lZTrQ7Kr8fNLKaSV2RqU7m1O8gzdNv 6EQB9M7Q/cpwkWSHLrkDDF3qNl0CGFzSX8DIl97Gf0C1btHVDnJQn+PjsAvgKQ== ARC-Authentication-Results: i=1; mx1.freebsd.org; none ARC-Seal: i=1; s=dkim; d=freebsd.org; t=1675710464; a=rsa-sha256; cv=none; b=QM2Cx92+/SxPgp+oeqBhju7J5oYS8xRyGUUS6c/IiuLJDIi5mBSkzjnsl7IPG/Fh5bPjPU lxI50bRGZt/ZKjFCW8Lipb4PIxGOKoVHlvdWXZMfqiG47Uow2i29bOoAKS/gmpnbraxbgF OH4mKRh/TeSNRgXJHi/qCbu5WXT3WqUgG0k0j/KTanqSnyCkyYMqPB55piSFsuQlsFY4ZP 9p+InTlTH5waSGraQXPshBYLV9ibSGZJh9IawiihcF9TUM2CSW4PsDQ8VvLKb89ICUx/ht gWqdpgzs1EODzcT/h9TXF3sAuU4evo+jWMmJzCbenChcarNXc9C/iXb+m1OJhA== 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 4P9bPD5K4Tzm0Q; Mon, 6 Feb 2023 19:07:44 +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 316J7iJE076881; Mon, 6 Feb 2023 19:07:44 GMT (envelope-from git@gitrepo.freebsd.org) Received: (from git@localhost) by gitrepo.freebsd.org (8.16.1/8.16.1/Submit) id 316J7i8J076880; Mon, 6 Feb 2023 19:07:44 GMT (envelope-from git) Date: Mon, 6 Feb 2023 19:07:44 GMT Message-Id: <202302061907.316J7i8J076880@gitrepo.freebsd.org> To: src-committers@FreeBSD.org, dev-commits-src-all@FreeBSD.org, dev-commits-src-branches@FreeBSD.org From: Dmitry Chagin Subject: git: bdb06df5ca6e - stable/13 - libthr: Fix pthread_attr_[g|s]etaffinity_np to match it's manual and the kernel. 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: dchagin X-Git-Repository: src X-Git-Refname: refs/heads/stable/13 X-Git-Reftype: branch X-Git-Commit: bdb06df5ca6e44af87b5246771c77e6b851b6f71 Auto-Submitted: auto-generated X-ThisMailContainsUnwantedMimeParts: N The branch stable/13 has been updated by dchagin: URL: https://cgit.FreeBSD.org/src/commit/?id=bdb06df5ca6e44af87b5246771c77e6b851b6f71 commit bdb06df5ca6e44af87b5246771c77e6b851b6f71 Author: Dmitry Chagin AuthorDate: 2023-01-29 12:35:18 +0000 Commit: Dmitry Chagin CommitDate: 2023-02-06 19:06:30 +0000 libthr: Fix pthread_attr_[g|s]etaffinity_np to match it's manual and the kernel. Since f35093f8 semantics of a thread affinity functions is changed to be a compatible with Linux: In case of getaffinity(), the minimum cpuset_t size that the kernel permits is the maximum CPU id, present in the system, / NBBY bytes, the maximum size is not limited. In case of setaffinity(), the kernel does not limit the size of the user-provided cpuset_t, internally using only the meaningful part of the set, where the upper bound is the maximum CPU id, present in the system, no larger than the size of the kernel cpuset_t. To match pthread_attr_[g|s]etaffinity_np checks of the user-provided cpusets to the kernel behavior export the minimum cpuset_t size allowed by running kernel via new sysctl kern.sched.cpusetsizemin and use it in checks. Reviewed by: Differential Revision: https://reviews.freebsd.org/D38112 MFC after: 1 week (cherry picked from commit 01f74ccd5a0d1a444703e931339709c7de5296b5) --- lib/libthr/thread/thr_attr.c | 6 ++++-- sys/kern/kern_cpuset.c | 6 ++++++ sys/kern/subr_smp.c | 2 ++ sys/sys/cpuset.h | 1 + 4 files changed, 13 insertions(+), 2 deletions(-) diff --git a/lib/libthr/thread/thr_attr.c b/lib/libthr/thread/thr_attr.c index 6ff23aa5a3da..5a06f793f4f8 100644 --- a/lib/libthr/thread/thr_attr.c +++ b/lib/libthr/thread/thr_attr.c @@ -599,8 +599,10 @@ _get_kern_cpuset_size(void) size_t len; len = sizeof(kern_cpuset_size); - if (sysctlbyname("kern.sched.cpusetsize", &kern_cpuset_size, - &len, NULL, 0)) + if (sysctlbyname("kern.sched.cpusetsizemin", &kern_cpuset_size, + &len, NULL, 0) != 0 && + sysctlbyname("kern.sched.cpusetsize", &kern_cpuset_size, + &len, NULL, 0) != 0) PANIC("failed to get sysctl kern.sched.cpusetsize"); } diff --git a/sys/kern/kern_cpuset.c b/sys/kern/kern_cpuset.c index affc48e78862..d2bbfff1337d 100644 --- a/sys/kern/kern_cpuset.c +++ b/sys/kern/kern_cpuset.c @@ -136,11 +136,17 @@ static struct domainlist cpuset_domains; static struct unrhdr *cpuset_unr; static struct cpuset *cpuset_zero, *cpuset_default, *cpuset_kernel; static struct domainset *domainset0, *domainset2; +u_int cpusetsizemin = 1; /* Return the size of cpuset_t at the kernel level */ SYSCTL_INT(_kern_sched, OID_AUTO, cpusetsize, CTLFLAG_RD | CTLFLAG_CAPRD, SYSCTL_NULL_INT_PTR, sizeof(cpuset_t), "sizeof(cpuset_t)"); +/* Return the minimum size of cpuset_t allowed by the kernel */ +SYSCTL_UINT(_kern_sched, OID_AUTO, cpusetsizemin, + CTLFLAG_RD | CTLFLAG_CAPRD, &cpusetsizemin, 0, + "The minimum size of cpuset_t allowed by the kernel"); + cpuset_t *cpuset_root; cpuset_t cpuset_domain[MAXMEMDOM]; diff --git a/sys/kern/subr_smp.c b/sys/kern/subr_smp.c index d66120666f9d..c83e05a4d87a 100644 --- a/sys/kern/subr_smp.c +++ b/sys/kern/subr_smp.c @@ -148,6 +148,8 @@ mp_setmaxid(void *dummy) KASSERT(mp_maxid >= mp_ncpus - 1, ("%s: counters out of sync: max %d, count %d", __func__, mp_maxid, mp_ncpus)); + + cpusetsizemin = howmany(mp_maxid + 1, NBBY); } SYSINIT(cpu_mp_setmaxid, SI_SUB_TUNABLES, SI_ORDER_FIRST, mp_setmaxid, NULL); diff --git a/sys/sys/cpuset.h b/sys/sys/cpuset.h index 601da08a46a8..f8fc36b99aa7 100644 --- a/sys/sys/cpuset.h +++ b/sys/sys/cpuset.h @@ -120,6 +120,7 @@ #include LIST_HEAD(setlist, cpuset); +extern u_int cpusetsizemin; /* * cpusets encapsulate cpu binding information for one or more threads.