From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mail.openvz.org (mail.openvz.org [69.168.225.77]) by lore.virtuozzo.com (Postfix) with ESMTPS id A1AB280067 for ; Thu, 19 Nov 2026 09:56:30 +0000 (UTC) Received: from mail.openvz.org (localhost [127.0.0.1]) by mail.openvz.org (8.14.4/8.14.4) with ESMTP id 6AJ9tIIp005083; Thu, 19 Nov 2026 12:55:19 +0300 DKIM-Filter: OpenDKIM Filter v2.11.0 mail.openvz.org 6AJ9tIIp005083 Authentication-Results: mail.openvz.org; dkim=fail reason="signature verification failed" (2048-bit key) header.d=virtuozzo.com header.i=@virtuozzo.com header.b="CX4BzgMz" Received: from mail-wr1-f71.google.com (mail-wr1-f71.google.com [209.85.221.71]) by mail.openvz.org (8.14.4/8.14.4) with ESMTP id 6AJ9tDcR005059 (version=TLSv1/SSLv3 cipher=AES128-GCM-SHA256 bits=128 verify=FAIL) for ; Thu, 19 Nov 2026 12:55:13 +0300 DKIM-Filter: OpenDKIM Filter v2.11.0 mail.openvz.org 6AJ9tDcR005059 Received: by mail-wr1-f71.google.com with SMTP id ffacd0b85a97d-48c6a1d4034so1492377f8f.0 for ; Thu, 19 Nov 2026 01:55:13 -0800 (PST) X-Forwarded-Encrypted: i=2; AL+hErF55LonwEkoOmOnes9c6e3MiUqJZxKkNN7VkndVraihBgGhjgsl/ATOD3+P/cE/0f6i34CGjQ==@openvz.org X-Gm-Message-State: APuU4Z+yA0+p5c2/q/AMuLhmEUjFUDJTOjiqiNFjYEW25v4GH4twhAHQ WtfeiwKk+501ImPNZ7lShS2xaj9L+HiUD7fU0ua613L8vXEfAqUBJq4xgIXQh5M/CyXD5urxzVa NT9tcBMU68R/+kApEBhXSImGZ4vx82eaKdnmrzuynEY/SvKnfIanFcA== X-Gm-Gg: AZFdTZdFgk5M7ti7V1HXjfjE4BdTThMO+oUAvZm4A1/Qm0IBTM8yBmvlmGD64a3j7IA IuY4NGxD81sttfi2LRV8qCSBDgUOQCc5yOMJGbLVp8+f7j69qUyTie3guJ7ghjg8Pc9TFDfoYK9 KZOsBSvMnozbrsS3NAAF2XqwEFhtTuh9W5GtsfsZ/kULD+DKbpg3k1KgMfeTky1Ru8vTHFrbzTJ oK9riva4e8a0AjSILItP8lsXE1gbLyZU3g+9u4/VohSq5sBhB2nWHzkU8Wou3a7/cIAeIMRrbzQ uMIuypLpzq8PTxMue5mZJce/usWrTfiyCWVgGW4Qp0nBFppmqnIT+jy8RC0QvQQavJ/7oW0BL6k WLF3znbG0DwFH98FLcZN/2ywLZgDyrA== X-Received: by 2002:a05:6000:288d:b0:4a8:1b63:215d with SMTP id ffacd0b85a97d-4a81b6325d6mr8500727f8f.27.1795082113366; Thu, 19 Nov 2026 01:55:13 -0800 (PST) X-Received: by 2002:a05:6000:288d:b0:4a8:1b63:215d with SMTP id ffacd0b85a97d-4a81b6325d6mr8500616f8f.27.1795082112558; Thu, 19 Nov 2026 01:55:12 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1795082112; cv=none; d=google.com; s=arc-20260327; b=iOec14p3WR0rypyZ8jk8UX7/FLPzkUSdX4PfYy5RVkh9sat+cPb/EZMPDhTHlvJlU8 XIpcnuuua33F7oZaTepJNm5Y5n3Z3EUiUrxLtNab1wuaI6iddLQ6fYTEB4IfgLXNQjFv jo/fjT1K1B6EWksNaS+DD4qPgjjHhCpqgCps/kQpk7oxE8oxPvgbr9c/3Q8274Q+AzQF ZdVatnuZXng9O9Wp7XxtkwOCKP14SfUpwQHAumYyXPsYwUN9DhX1zsjmFfSGIiHaRpp6 wYA52f101j7w5loGZKMGWjqWtCbgXaSR7SSdi1TNh3xrPTLTsxvObCG8YxVcfPo4q+wr GwsQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20260327; h=cc:to:in-reply-to:references:message-id:content-transfer-encoding :mime-version:subject:date:from:dkim-signature; bh=l0beUfiD9i3NU/4LthUbFbCp3URurvGlMmQCgshEEZE=; fh=xzZN5FxA6K5vnZjs05BDvWEzDJehiW/Et4hvm7b4Tvs=; b=fTKjab0nioUAqyhHtKkG2nw7bd+pLGBWy34HPbQHEdNe5C+TH6/tbWBev4FKAiaVbv R85IzNsS4eioxD3MfKSsYk7YCbPTVuLUYft52lZHUkJHlIsmBE/tHRgRA0T3k33Uwh8W 2bxtEAAGa+CQ5ZCtMy9Fc3qjlR47ymEh26MnG5UNj9a/qdAMnzgDq4P/pyPvQcECa6XT Yx3azvG6uSqx2Wy7/IuB/+BWCRStuPiHclkHWw2/hK68AM/QLKvPr8RA/4vyLZOsgF4t DfHvP+VIovZDdOCQhtWfNKBOC1aIQALeMJh6aLUHd7vzphh7WX87J4u4IAnNBo0Om+vQ NqLg==; dara=google.com ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@virtuozzo.com header.s=relay header.b=CX4BzgMz; spf=pass (google.com: domain of vladimir.riabchun@virtuozzo.com designates 130.117.225.111 as permitted sender) smtp.mailfrom=vladimir.riabchun@virtuozzo.com; dmarc=pass (p=QUARANTINE sp=QUARANTINE dis=NONE) header.from=virtuozzo.com Received: from relay.virtuozzo.com (relay.virtuozzo.com. [130.117.225.111]) by mx.google.com with ESMTPS id ffacd0b85a97d-4a658126142si10038474f8f.198.2026.11.19.01.55.12 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 19 Nov 2026 01:55:12 -0800 (PST) Received-SPF: pass (google.com: domain of vladimir.riabchun@virtuozzo.com designates 130.117.225.111 as permitted sender) client-ip=130.117.225.111; Authentication-Results: mx.google.com; dkim=pass header.i=@virtuozzo.com header.s=relay header.b=CX4BzgMz; spf=pass (google.com: domain of vladimir.riabchun@virtuozzo.com designates 130.117.225.111 as permitted sender) smtp.mailfrom=vladimir.riabchun@virtuozzo.com; dmarc=pass (p=QUARANTINE sp=QUARANTINE dis=NONE) header.from=virtuozzo.com DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=virtuozzo.com; s=relay; h=Message-Id:Content-Type:MIME-Version:Subject:Date :From; bh=l0beUfiD9i3NU/4LthUbFbCp3URurvGlMmQCgshEEZE=; b=CX4BzgMzIDf/GagszCt TBfZ3/gGFcZbQqMVUsCVfVswt4RrErCSWOLFuuye8j1xWMTdAyWb4V03cOYDV+NBr11jltUi3AKH1 GnYxGuzmCyTWhA1TUMN1lIHUyZNoaQmAJl2VYEuYCmTtxt/3ZT9PTpM0V18kwaT8RLbeQVoIsMTYp OWF7Ta6oM31K949l+qHebbO0XfU15wGfaKhnj5T0CwrmuTprIXYvMyHFcD/q0MzUtkOBzya3U8xuu NFiqwhlWOEhFbZ9GhhanLWHCd2nfhMq8Ad60fucNTnZ0FRWm6Bt/bn1+WXOIpNzlHeasSn9J5xQKB vqa98s/chtk963Q==; Received: from ch-demo-asa.virtuozzo.com ([130.117.225.8] helo=192.168.1.87) by relay.virtuozzo.com with esmtps (TLS1.3) tls TLS_AES_256_GCM_SHA384 (Exim 4.96) (envelope-from ) id 1xTymy-00AqCt-2r; Thu, 19 Nov 2026 10:55:10 +0100 From: Vladimir Riabchun Date: Thu, 19 Nov 2026 10:54:02 +0100 MIME-Version: 1.0 Message-Id: <20261119-ct-invalid-nrpoc-v5-1-ff22216f458b@virtuozzo.com> References: <20261119-ct-invalid-nrpoc-v5-0-ff22216f458b@virtuozzo.com> In-Reply-To: <20261119-ct-invalid-nrpoc-v5-0-ff22216f458b@virtuozzo.com> To: Konstantin Khorenko X-Mailer: b4 0.16.0 X-OZ-Fwd: true Cc: devel@openvz.org, Sashiko Subject: [Devel] [PATCH hci-8.1 v5 1/2] sched: Fix sched_getaffinity syscall X-BeenThere: devel@openvz.org X-Mailman-Version: 2.1.12 Precedence: list List-Id: OpenVZ development List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit Sender: devel-bounces@openvz.org Errors-To: devel-bounces@openvz.org We observed incorrect cpu numbers inside containers: [root@localhost ~]# nproc 64 even when there were much less physical/virtual CPUs. The root cause is incorrect bitmap_fill usage - it sets whole longs only, without handling bit tails, so the actual number of set bits is 64 = bits in ULONG. If we use cpumask only or vcpus only, nproc and other getaffinity users will get incorrect info about CT resources. We can't run on more than count(cpuset) CPUs and we are limited by vCPU number. So the minimum of these two is the real limit. Return first bits set - anyway they can't be used for anything except counting from inside CT. Host behavior is not changed. It is also intentional that we perform VE check against current exec env - CT users will get virtualized view and host users will get real affinity without vCPU info. This fixes only getaffinity syscall, its value may be lower than /proc/cpuinfo or /sys/devices/system/cpu/online. This is expected. https://virtuozzo.atlassian.net/browse/VSTOR-141682 Fixes: 17e30fe0e094 ("sched: Return only virtual cpus in sched_getaffinity()") Feature: sched: virtualize CT cpu affinity management Reviewed-by: Sashiko Signed-off-by: Vladimir Riabchun --- kernel/sched/syscalls.c | 18 +++++++++++++----- 1 file changed, 13 insertions(+), 5 deletions(-) diff --git a/kernel/sched/syscalls.c b/kernel/sched/syscalls.c index 6d921043e9e7..274d897f52cd 100644 --- a/kernel/sched/syscalls.c +++ b/kernel/sched/syscalls.c @@ -1316,15 +1316,23 @@ long sched_getaffinity(pid_t pid, struct cpumask *mask) if (retval) return retval; + scoped_guard (raw_spinlock_irqsave, &p->pi_lock) { + cpumask_and(mask, &p->cpus_mask, cpu_active_mask); + } + if (!ve_is_super(get_exec_env())) { + /* + * setaffinity is a no-op inside CT, so these bits + * can only be used for counting. + * We can't have more than vcpus and we can't run on CPUs + * outside the mask. Reporting smallest will provide true + * information about CT resources. + */ + unsigned int vcpus_avail = min(task_nr_cpus(p), cpumask_weight(mask)); cpumask_clear(mask); - bitmap_fill(cpumask_bits(mask), num_online_vcpus()); - return 0; + bitmap_set(cpumask_bits(mask), 0, vcpus_avail); } - guard(raw_spinlock_irqsave)(&p->pi_lock); - cpumask_and(mask, &p->cpus_mask, cpu_active_mask); - return 0; } -- 2.52.0 _______________________________________________ Devel mailing list Devel@openvz.org https://lists.openvz.org/mailman/listinfo/devel