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 BF94780E7E for ; Wed, 28 Oct 2026 12:48:01 +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 69SCknc9020067; Wed, 28 Oct 2026 15:46:49 +0300 DKIM-Filter: OpenDKIM Filter v2.11.0 mail.openvz.org 69SCknc9020067 Authentication-Results: mail.openvz.org; dkim=fail reason="signature verification failed" (2048-bit key) header.d=virtuozzo.com header.i=@virtuozzo.com header.b="dp/SnvGH" Received: from mail-wm1-f69.google.com (mail-wm1-f69.google.com [209.85.128.69]) by mail.openvz.org (8.14.4/8.14.4) with ESMTP id 69SCkiCq020050 (version=TLSv1/SSLv3 cipher=AES128-GCM-SHA256 bits=128 verify=FAIL) for ; Wed, 28 Oct 2026 15:46:44 +0300 DKIM-Filter: OpenDKIM Filter v2.11.0 mail.openvz.org 69SCkiCq020050 Received: by mail-wm1-f69.google.com with SMTP id 5b1f17b1804b1-4a028616bebso6799045e9.1 for ; Wed, 28 Oct 2026 05:46:44 -0700 (PDT) X-Forwarded-Encrypted: i=2; AKwUvBxJrHq5y6yudw6DiSMBhqiG2ENkOo21Syr3nYsaq7xbyDhIuWzsLwLFK0KS+W3m8++Hhr98Mg==@openvz.org X-Gm-Message-State: AFq9FYKfD9f2DgBZMvC/3m0xfAA/RikVa0DPG6/QEUnWLcReZj/EH/6A lIQGKfSB8RC2W3FYeQVctlmwMRuWffVz8UK5JzNdaycx/x6lHWAlZelynpa+2uQv0Jjom+WowWC YyFrB/KEXDHrfA5ZBWKyFD0kqcOQ8teWOwxtJALbdKfUbZ4aA1lGHYA== X-Gm-Gg: AYBFou2SG3b5iFaDZMfzbVSPLzPrJBcPeER7EVkKrleWh42NgA4/894Y3dB4cRIf01N EmKGf1kSKWJUeTBw+gaorOt1tKHIEW3cyP4t4VJQV/vQhLKcT6zKgFcONEqhOxSEMQo2fJpYsic A1Wk7ruUKuQ4LbBD7LRNbU7oB41AnPxUPRjcPO/ooE8LSOGZk0HHbP9B2XP7NSVhc0uD29hjUto mhnD1FbNiZBdvCWfbOee747sYwKA8lathCehKijNuZ0v8bU/UtM2a3Ju5T6RuiJguplKN2Vb5BX e2S4EaWiL6vSQINp4ZJdNdPwYkhyNkQB9LAAX7ZkXSp5lAB1x3PfcSLOC20BrB1/s7uuzQPlXIA 4I6Sclm9zFirMG84v9lbBvcNzfetx X-Received: by 2002:a05:600c:6207:b0:4a8:f2ad:a9e5 with SMTP id 5b1f17b1804b1-4a963d1b467mr49559845e9.3.1793191604302; Wed, 28 Oct 2026 05:46:44 -0700 (PDT) X-Received: by 2002:a05:600c:6207:b0:4a8:f2ad:a9e5 with SMTP id 5b1f17b1804b1-4a963d1b467mr49559375e9.3.1793191603746; Wed, 28 Oct 2026 05:46:43 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1793191603; cv=none; d=google.com; s=arc-20260327; b=iunqy6wgfo5mNNpiCnJ0vcH+jrkOTXQuUinxyREOOKKaKkl39r1wXcmtFOHQFP0ILs qYghhli9oQYIsz0+OK6EAuIveP++38l/hPF07UIig5UcNka3nHZu/790JIJ2hRhikN/b 8Z407UBNyuyVT5FYouA9YsYeEyKAC/CFiF+yRqYN1zWpHENzPW3Yq8mrl8e0iADi72n0 Gb9Vn+EN+1Kg7/18PEv5qEw0MHKero2vBPaxs9jPL7WjUmnxjKcW6lq021tGxQYBZb3a wuzpHgsNoYHqCrS6L15NFYtM5TGLMx1iEEKw0qgbl3/0067Hal9mXesg0wtKwtoZGjvU 7dZg== 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=P4qdSVARVXZDEvGSgSI9eBtPcUBh65SXpdMVSyJUtKM=; fh=5hQRK+XZF8m8FADH0g5yAiDkSoTAVGTSxnnvVVATGZQ=; b=Q+BA2oiwuOJaHbtQnxoYfdDO2MwE/eBwkpCmXDUyxB6LCZwUUVmrtuXnVu/N8sc0nC REyxPf0beOu9D9+LFHiQZboF321uYNMr2cuTO1Rc4rFUe05M6e3+nkGfkagy7sfFUdcL vpIySHEPB1GQdDTuSxrhCkwN7bSW7y2eRC3c9Pxj92JnesWnJdKte+kaETUd3PG/F9Vd ZJ2SAieCbpL3DbtWL8yxhrQfxr7NAT8UOE4H0yJs5lKXUpxmbOGz+swHWFUanSW4sM3O hy+pADSZlxN0+rX4W06xOdIkLIH2g4aya4wGRBu18ifZ9g8itfmzu96pUul++Dn8xqIi AL3A==; dara=google.com ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@virtuozzo.com header.s=relay header.b="dp/SnvGH"; 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 5b1f17b1804b1-4a97e009809si37340165e9.17.2026.10.28.05.46.43 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 28 Oct 2026 05:46:43 -0700 (PDT) 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="dp/SnvGH"; 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=P4qdSVARVXZDEvGSgSI9eBtPcUBh65SXpdMVSyJUtKM=; b=dp/SnvGHBEt1eUXGqG9 ml9xIZiureQiyrFCayZZGX5z1UpRQWYzm8wszWth1RKxXEWGu+tbu1o8ng8GjBvAo8iBDVNBthWsc g3ZQOp8N5M5vyqzD2/Sbb/GE0+It5xw9DD9tXBJxSqZLubVd1bSNFz8ksgGZbkRHnY2Y/VcxsIN2C aHDzjGjZ8q3o2WiPuw3L16dz6c2cGYcJWs8YJxnG1TER1lDRADhQPLBeXuYB60wyfWh/Gbk0VBzEM Md8kVxnrcbtVI/CgNR37lDsWHYPSSZkgia7M+DnM+4H03ksTsPjMqNcjUXqsbGGtpwIdeDGjoBYx3 SD44tFb8rCuz0jg==; 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 1xM2zR-007lg7-0m; Wed, 28 Oct 2026 13:46:42 +0100 From: Vladimir Riabchun Date: Wed, 28 Oct 2026 13:46:37 +0100 MIME-Version: 1.0 Message-Id: <20261028-ct-invalid-nrpoc-v2-1-968fe985ce27@virtuozzo.com> References: <20261028-ct-invalid-nrpoc-v2-0-968fe985ce27@virtuozzo.com> In-Reply-To: <20261028-ct-invalid-nrpoc-v2-0-968fe985ce27@virtuozzo.com> To: ptikhomirov@virtuozzo.com, Konstantin Khorenko X-Mailer: b4 0.16.0 X-OZ-Fwd: true Cc: devel@openvz.org Subject: [Devel] [PATCH hci-8.1 v2 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 integers 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. https://virtuozzo.atlassian.net/browse/VSTOR-141682 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..265d3a96d227 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 not available 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(num_online_vcpus(), 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