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 7D4588017D for ; Wed, 18 Nov 2026 19:44:23 +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 6AIJh97w028671; Wed, 18 Nov 2026 22:43:10 +0300 DKIM-Filter: OpenDKIM Filter v2.11.0 mail.openvz.org 6AIJh97w028671 Authentication-Results: mail.openvz.org; dkim=fail reason="signature verification failed" (2048-bit key) header.d=virtuozzo.com header.i=@virtuozzo.com header.b="s6bOxCoI" Received: from mail-wm1-f70.google.com (mail-wm1-f70.google.com [209.85.128.70]) by mail.openvz.org (8.14.4/8.14.4) with ESMTP id 6AIJh8GU028659 (version=TLSv1/SSLv3 cipher=AES128-GCM-SHA256 bits=128 verify=FAIL) for ; Wed, 18 Nov 2026 22:43:08 +0300 DKIM-Filter: OpenDKIM Filter v2.11.0 mail.openvz.org 6AIJh8GU028659 Received: by mail-wm1-f70.google.com with SMTP id 5b1f17b1804b1-4a17741243eso7945475e9.0 for ; Wed, 18 Nov 2026 11:43:08 -0800 (PST) X-Forwarded-Encrypted: i=2; AL+hErGvz1MO9z40bL3WOL+uFBuJVpTaItW67rdDO7GwtuXuLwaRADr9ODCu7qt2hgn0ccuVUWmMmg==@openvz.org X-Gm-Message-State: APuU4Z+fBVdaSL9eGOajQZpL37Pu58+o9Np4pf1pvQIrsnVcUd0RVKRN P5hkELNuWyvJVPNKZCPof6mny7Zs2kLyThnZZotS31XS818tm+4dmGHJdzDtvrZqpokt3XcJlAj PN+MF79ap9B7tRmtrpr04AFXTCYzJ+6pZFKMVjfE9KVPwPRz2WNARQg== X-Gm-Gg: AYBFou0gURYEensh7xQtY6XT9IBnEmnrpoLr4GirVWZPny8XQLmtElFV1OvEdPtMNr5 heW32698+D8hR2ko8/5KnworPiUjKED+v90pCP9jHy8teF4fql73yd4MuEB2f3vp66zpB4o9JKA qUO3T5ekgGCqaccmwNkYinN3WITVL/h/a8WnkAGl0ooHb5W4egCu6cV4qCYuQZLY7GtFKxmI1Az 0wsgwV1xAP3Iafnr15eSg4tju3ZIqc+K6p1Qf0qhR5O/PHIbo2/7beo3zC2jdXrNAJXwTm2tSl3 SAgEpx19IlFX6yxzN2LnWqR/0k1sfT4K8zXVHAcmtzhsGY7fqLV3sZENuVkHLLO2CitlTkXLp8A jdP2KCCo8vi4I+Kz+mjOzAxvrdG9l X-Received: by 2002:a05:600c:3494:b0:4a2:267:25b3 with SMTP id 5b1f17b1804b1-4bb7da4efd4mr69078685e9.35.1795030988079; Wed, 18 Nov 2026 11:43:08 -0800 (PST) X-Received: by 2002:a05:600c:3494:b0:4a2:267:25b3 with SMTP id 5b1f17b1804b1-4bb7da4efd4mr69078285e9.35.1795030987523; Wed, 18 Nov 2026 11:43:07 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1795030987; cv=none; d=google.com; s=arc-20260327; b=NzCioWIyRwUyZREMLJFV9PMw7sA6Qo/DmiQUCu5HX9VzhrjVY7AeQlMqsjjM05zIAL VMOChq1NenLC33j2Y5wXTWRTJVzNWKlF0UZEYlGkLjXMnPDm0q/AjWVwDtesCBfPHIYX RDo1BVvjGgg0F/SKpkRlsOE/eBzM8RcnYjfCS7b8kmpNsA+QUuz6zzb75457C5LRxczk Lc8X4T1/ghlQSEOef7XI322fOc1+J9+e0KAZNTGCDlfKHlh5kWPdhBlLnw2Cu2M8oKTB kAeKM7sfIX98Kq3j2O7ktIAIPwmcTl6lr3iZXhAOuqjp+66rgxUG36F0VlLyw4xrs3NM 0rlA== 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=q8B81Oc45ggFpL925s+BO0UlMx6TIIGa89GDHtrZPME=; fh=4dppuILCfGifWHfxjIIA1BWoKQtGs1EMopxlFiqV6no=; b=i42MNCOcnymk2S6tjZFmMHUGtKBRF7gM74oFnVSaIX85bUtxFl5j3k+WaAQ1VTriu+ ZoIres0MWrXb6YVZQYVTOpVDyhH1mWO0QJwGG2H9lbnTXwhywv59cKRkx0g3iXyKmfgO lzXM8mjLvSwim7sk0uKUoIXRtbdncxuyWOk32tOD1vEYgiBfVLYSUhaBE6BwM5q2Oyo6 8s8nM97Ro2XI4oGxIqXZhQC2DddFY93s4njWU2/k8qUB0rLYrznHujbMCFWKIo7uwlrs tEtA5Zjz8iwPSyQcTUex7v17e+VUOc2YdRXjrCF1CAZAFi+ayIbTLVxf+5GJ3Ira6E9b XKjw==; dara=google.com ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@virtuozzo.com header.s=relay header.b=s6bOxCoI; 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-4a659546485si6791697f8f.290.2026.11.18.11.43.07 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 18 Nov 2026 11:43:07 -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=s6bOxCoI; 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=q8B81Oc45ggFpL925s+BO0UlMx6TIIGa89GDHtrZPME=; b=s6bOxCoIZbmdlf8uUMO AVQfMVlV5I1Rn0PagN9bmZn2y+IEF6s9KrBDOmqdFOHyYU3QrySeaSMkc9Om7vtRxiTbBBY3OmAnY sKUr6Twek0H3sAVgvkziu4BpzLh240IYcV2Hx73EQSeKld3qAkY/Zo5tYbT+J1ms5Lgepw7HkVnVQ yFxnAy15XqTYiUGTCHAjIDZt9qfuLL5mWjmr7RRIIjs0j/r/TBAgN2nyr4fGLBDlZP+PTRnKicNst jqfxOLcui5PHqZkmx1tZSjhLMhb2Nc2CLujdrTCxEJnofobnB/Cy9gbfA2gv3iWJTEkGs/mQCGcD2 FpyAz6n7DKN/etQ==; 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 1xTlUO-00CGqR-2Z; Wed, 18 Nov 2026 20:43:06 +0100 From: Vladimir Riabchun Date: Wed, 18 Nov 2026 20:43:00 +0100 MIME-Version: 1.0 Message-Id: <20261118-ct-invalid-nrpoc-v4-1-30baaeda3f87@virtuozzo.com> References: <20261118-ct-invalid-nrpoc-v4-0-30baaeda3f87@virtuozzo.com> In-Reply-To: <20261118-ct-invalid-nrpoc-v4-0-30baaeda3f87@virtuozzo.com> To: Konstantin Khorenko X-Mailer: b4 0.16.0 X-OZ-Fwd: true Cc: devel@openvz.org Subject: [Devel] [PATCH hci-8.1 v4 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 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