From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mail.openvz.org (unknown [69.168.225.77]) by lore.virtuozzo.com (Postfix) with ESMTPS id 02C4380726 for ; Tue, 6 Oct 2026 22:14:24 +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 696MDA6x028361; Wed, 7 Oct 2026 01:13:11 +0300 DKIM-Filter: OpenDKIM Filter v2.11.0 mail.openvz.org 696MDA6x028361 Authentication-Results: mail.openvz.org; dkim=fail reason="signature verification failed" (2048-bit key) header.d=virtuozzo.com header.i=@virtuozzo.com header.b="UyHj5dpo" 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 696MCxfE028322 (version=TLSv1/SSLv3 cipher=AES128-GCM-SHA256 bits=128 verify=FAIL) for ; Wed, 7 Oct 2026 01:13:00 +0300 DKIM-Filter: OpenDKIM Filter v2.11.0 mail.openvz.org 696MCxfE028322 Received: by mail-wr1-f71.google.com with SMTP id ffacd0b85a97d-48c511d9e97so1822470f8f.0 for ; Tue, 06 Oct 2026 15:12:59 -0700 (PDT) X-Forwarded-Encrypted: i=2; AKwUvBwIhkXFhGFIyW4ie2VTQwdSnBecMJmUErFaAzWLAKTVH2Sz3eq2t/todnMNnKerYAxQDXP/5Q==@openvz.org X-Gm-Message-State: AFuF++mTNqK7vsOzQYW2FgcmjGGNq6xVMNWZCwvaI/cJOdw3i0FI64El OqPyebi2jJVQwiXhHkR3y4OLvFCWySa3iMekkTluhRpVwLu7pKkY9Qd5d9utvVGTqtMqiEA9Ow6 34o7yX5UmhgA8R3YnZt9vfZtEDnCFKgcLzA6xmXZa11mp/QljP+WcMA== X-Gm-Gg: AYBFou1O1NLwQBXEg7mKh39DSfBlDMUoiX7G/r/pO4OLNHjbhxecw/oKPhYO933RvZ9 eDl0T0YyO+laSNykChHHSu3VVd6Fa0sWAez5EKnQLaM58UHbTJQNAfxgCWt7yLOkR+ClSXf4dbB Uqy3bB7PlnW2Zmxwh48TtdT5CV5W8jV5WS+yoMwo05WvjeMhqOcAFp0W2+Myv7G7jiXFebT1Xwh w5CELaDpMQOgqrcanuGqqP3DV/hh1YR7o4WmcZPFBXwP9lVMd1D9s4DTERc0hAnZCYdq57UgMoH 55iGGX8D2i6MH1IiSufGFQt4NGk+zbDfFJc3c+6v5DKzcrlE9WvKtTes2F5e7G56b94ZEl/1uWi fXEMZwk1xV03ZF1hg X-Received: by 2002:a05:600c:4e43:b0:4a0:2391:6529 with SMTP id 5b1f17b1804b1-4a180455415mr2433465e9.29.1791324779635; Tue, 06 Oct 2026 15:12:59 -0700 (PDT) X-Received: by 2002:a05:600c:4e43:b0:4a0:2391:6529 with SMTP id 5b1f17b1804b1-4a180455415mr2433165e9.29.1791324779079; Tue, 06 Oct 2026 15:12:59 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1791324779; cv=none; d=google.com; s=arc-20260327; b=iJxrpQltb6YQo6zR9oACQzbjny+Mg28PS1azsjJXYk4XOiroJRISUa/M0PDb+PoRRd PzyNjDIfZvcqDc0WimJETYYksU2Lj5g+T38ORfh7kv3/8pDdCXLtBdkFpnXMZ2Qs14NC 2RxDR7fL2QnttdOnNjTtdDGJ/OQkdGA3WDi0nQEeRvHvIHwofcHxMgUufZTkHjW/yOml eX4iBw+onghRH4oxlobRNnaM145J6x1tMalLcl/CXauecUZwZfEct4oM/P0cEle2DUCY g1yaHRQDF8HLIWOiy/qwDJo9d/6iaiLyXdPg0tqFP79QCVCfsXTNKCUOIWRhzTfxWg9N vk/w== 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=W1sZ/If0ZxtS5ax2Tw4PE/Nt8WLp+A6q5qCaitDvrXQ=; fh=bRkZfFa6377EgOVW8zBDri2gGIQqe/ZeiH+ijEM/ROI=; b=A2n4i0Ao9rMJdpdVc6NGJJMF8m+I5jryHrD0MGETCN7By4vmnypXdCjkZj5W28JKsd w8CAUxZr3Afxb6WRNQUOmtKzP4LThPNRPZfKhobdXaoVN8Ljqs/FgSQRP9PtsND1dQUe 5V0xvVsForaLX56S3DY3tfm5R5bFQ885y3TpDnIYKPcAayG6wNdq2BF6d9QukbfEyg+P C8XS0G89QR7pgNBSFgGvsWpHkdEYWXLdy/oTRgyC3JRWIe0wx8lr3XdhXE55lpgRYS/7 58X5OyNHBX/DWhobLFUQpu07UwqGrsKZ2BKuLdSWHJizAEMneshXGOrIKWIn6iwmZiaY nQjA==; dara=google.com ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@virtuozzo.com header.s=relay header.b=UyHj5dpo; spf=pass (google.com: domain of khorenko@virtuozzo.com designates 130.117.225.111 as permitted sender) smtp.mailfrom=khorenko@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-4a17a51642esi79476595e9.7.2026.10.06.15.12.58 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 06 Oct 2026 15:12:59 -0700 (PDT) Received-SPF: pass (google.com: domain of khorenko@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=UyHj5dpo; spf=pass (google.com: domain of khorenko@virtuozzo.com designates 130.117.225.111 as permitted sender) smtp.mailfrom=khorenko@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=W1sZ/If0ZxtS5ax2Tw4PE/Nt8WLp+A6q5qCaitDvrXQ=; b=UyHj5dpo5Ol1lb4uotS PkX8I9Cjby5Ng7jVltx1JwVkcvDTq40P949ItlcE/JtUCrO1IHDcO5UuYErkSJCnB7F2pF2Qg1KhD KfAhydmAImvdsukUvObZUtxgIWc4z/In4VxP0cWnbrvcDfXAKeOQekEXwEOgZaG60hZQAHVQkidiH UoXSicLdpIxkN8FIIbfFvpRJy+7m2zbSU7PkdiLJsBFuRDEaHALWyzs7gmiNZByQZSzYbAY2Y04RI a3aAxU+/wfcDwlG4LrF7U8sf4ja85p57TlCj1jCiFabzjaWjWZ4dr6lyCTMx8IdYTwmLtHm8tROET AKMKSyLrG4/3Hyw==; Received: from ch-demo-asa.virtuozzo.com ([130.117.225.8] helo=f0.sw.ru) by relay.virtuozzo.com with esmtp (Exim 4.96) (envelope-from ) id 1xEDLt-004aGG-1E; Wed, 07 Oct 2026 00:12:48 +0200 From: Konstantin Khorenko Date: Wed, 07 Oct 2026 00:12:53 +0200 MIME-Version: 1.0 Message-Id: <20261007-b4-prep-khorenko-vstor-148656-cpuid-v4-3-bf16c29bea24@virtuozzo.com> References: <20261007-b4-prep-khorenko-vstor-148656-cpuid-v4-0-bf16c29bea24@virtuozzo.com> In-Reply-To: <20261007-b4-prep-khorenko-vstor-148656-cpuid-v4-0-bf16c29bea24@virtuozzo.com> To: Pavel Tikhomirov , Vasileios Almpanis X-Mailer: b4 0.16.0 X-Developer-Signature: v=1; a=openpgp-sha256; l=5109; i=khorenko@virtuozzo.com; h=from:subject:message-id; bh=qoy3bmXg4wwjekOfouDwfQbfbCHTw0MWxeMPAEHvIBo=; b=owEBbQKS/ZANAwAKAVGWCkf5YVwqAcsmYgBqxXJoO91n/T2MEo7rg7qwLe3ganwPYSWk8OxMJ hoVBdOScsmJAjMEAAEKAB0WIQRWD23IPcXT0GO9CCxRlgpH+WFcKgUCasVyaAAKCRBRlgpH+WFc KpGBEACmc6rqyt60wg8Ubo1Pw1/fjnht1XX1NxVNm+0p/cHKJIqycWE6a9uUJNo0SHv1GHrIkws iZ0b5bEpm9LIubSiqWiBcH2pBUYevCuzf7Df6jJCigco6UNgWb4L7DT6IPPhzcKj7WnjKPCEq1+ H8sK+hPxck23VcfKG+c+bFqgmKBXgYTWI2+Np220YRDIrD/v45Z1S1QbELhygt9s7JthrXjHQRf BzTBT8mcMN0ngLEl8vYQLiu9vN55VcCSJpMyAKF7D13u94+bwke19Mlzcf3hqUbinthIL6TC9hm vSvXRFFJeUMx+3XarFRXuhgY1jDVR76IB/IQz+E6vxv9RD9sMC80ZX/D77J8ZCKLNfYf2ox1LTJ /Vc6XSylF9Ok0DA0HuK+g/pLOLHR3e53W4gcszDq725S5KUaVgFrngB8ncvLtwH6XK5bfsWaBGE XIK/vgpUHYZP7bwSiRqFQtL/UeDGgecDLmvytLDHJjcUv1xWYgJo9gdtuJnDGmso5Z0xvNcm/9Y v0kv2g79BWeGBd6vk12p5CfUALZZz9HQvNqc38OuiB3haL8p1lij5lwlqQI5vBeIeNxyZk9t3tO Jgd1ZFMG4yM2w44C2tdk0Lqxn4GAwkiz+WLdJwYcZ3r3MfKUBFmNyuNyrOt2N7vENMFmxgbdqpP UtX5CBDXGP/aRvw== X-Developer-Key: i=khorenko@virtuozzo.com; a=openpgp; fpr=560F6DC83DC5D3D063BD082C51960A47F9615C2A X-OZ-Fwd: true Cc: devel@openvz.org Subject: [Devel] [PATCH hci-8.1 v4 3/5] selftests/ve: check CPUID override right after entering a VE 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 Add a case where the child executes CPUID straight after unshare(), without stopping or blocking in between, and expects the table values. Before the kernel change the override took effect only after the first context switch, so the child saw the hardware values. A tick can still preempt the child in that window, so the case runs the sequence several times: a kernel that arms faulting only at the switch has to get lucky every time. https://virtuozzo.atlassian.net/browse/VSTOR-148843 Feature: x86: cpu pools (cpuid override) Signed-off-by: Konstantin Khorenko --- .../testing/selftests/ve/ve_cpuid_override_test.c | 62 ++++++++++++++++------ 1 file changed, 45 insertions(+), 17 deletions(-) diff --git a/tools/testing/selftests/ve/ve_cpuid_override_test.c b/tools/testing/selftests/ve/ve_cpuid_override_test.c index f2883539bac3f..d940acc7ee792 100644 --- a/tools/testing/selftests/ve/ve_cpuid_override_test.c +++ b/tools/testing/selftests/ve/ve_cpuid_override_test.c @@ -31,6 +31,7 @@ #define CPUID_OVERRIDE_PATH "/proc/vz/cpuid_override" #define CPUID_LEAF 1 #define CPUID_LINE_LEN 128 +#define NO_RESCHED_ROUNDS 20 /* The kernel takes a table back only in one write below a page. */ #define CPUID_WRITE_MAX 4096 #define CPUID_SAVED_MAX (CPUID_WRITE_MAX + 1) @@ -49,14 +50,15 @@ static void do_cpuid(unsigned int leaf, struct cpuid_regs *r) struct child_ctx { int result_pipe[2]; + int stop; }; /* * The child enters a fresh VE, so it is armed with the table state of that - * moment, then reports its view of the leaf to the parent over a pipe. It - * stops itself in between: a stopped task is off the CPU, so the resume is - * a context switch, and the parent may change the table while the child - * stands still. + * moment, then reports its view of the leaf to the parent over a pipe. With + * @stop it stops itself in between: a stopped task is off the CPU, so the + * resume is a context switch, and the parent may change the table while + * the child stands still. */ static int cpuid_child(struct child_ctx *ctx) { @@ -66,7 +68,7 @@ static int cpuid_child(struct child_ctx *ctx) if (unshare(CLONE_NEWVE) < 0) return 21; - if (raise(SIGSTOP)) + if (ctx->stop && raise(SIGSTOP)) return 22; do_cpuid(CPUID_LEAF, &r); @@ -148,7 +150,7 @@ FIXTURE_TEARDOWN_PARENT(ve_cpuid_override) close(cgv2_fd); } -/* Fork the child into the VE and return once it stands still there. */ +/* Fork the child into the VE; with @stop return once it stands still. */ static pid_t spawn_cpuid_child(struct __test_metadata *_metadata, FIXTURE_DATA(ve_cpuid_override) * self, struct child_ctx *ctx) @@ -170,16 +172,20 @@ static pid_t spawn_cpuid_child(struct __test_metadata *_metadata, ASSERT_GE(pid, 0); close(ctx->result_pipe[1]); - ASSERT_GE(waitpid(pid, &status, WUNTRACED), 0); - if (!WIFSTOPPED(status)) { - /* Reaped: the pid may be reused, keep it from teardown. */ - self->child = 0; - if (WIFEXITED(status)) - TH_LOG("child exited with %d", WEXITSTATUS(status)); - if (WIFSIGNALED(status)) - TH_LOG("child killed by signal %d", WTERMSIG(status)); + if (ctx->stop) { + ASSERT_GE(waitpid(pid, &status, WUNTRACED), 0); + if (!WIFSTOPPED(status)) { + /* Reaped: the pid may be reused, keep it from teardown. */ + self->child = 0; + if (WIFEXITED(status)) + TH_LOG("child exited with %d", + WEXITSTATUS(status)); + if (WIFSIGNALED(status)) + TH_LOG("child killed by signal %d", + WTERMSIG(status)); + } + ASSERT_TRUE(WIFSTOPPED(status)); } - ASSERT_TRUE(WIFSTOPPED(status)); return pid; } @@ -208,7 +214,7 @@ static void collect_cpuid_child(struct __test_metadata *_metadata, TEST_F(ve_cpuid_override, ve_sees_table_host_sees_hardware) { - struct child_ctx ctx; + struct child_ctx ctx = { .stop = 1 }; struct cpuid_regs r; pid_t pid; @@ -229,7 +235,7 @@ TEST_F(ve_cpuid_override, ve_sees_table_host_sees_hardware) TEST_F(ve_cpuid_override, flushed_table_falls_back_to_hardware) { - struct child_ctx ctx; + struct child_ctx ctx = { .stop = 1 }; struct cpuid_regs r; pid_t pid; @@ -244,4 +250,26 @@ TEST_F(ve_cpuid_override, flushed_table_falls_back_to_hardware) EXPECT_NE(r.edx & self->bit, 0u); } +/* + * The child does not block between entering the VE and the CPUID, but a + * tick can still preempt it there. Repeat, so that a kernel which arms + * faulting only at the switch has to get lucky every time. + */ +TEST_F(ve_cpuid_override, armed_before_first_reschedule) +{ + struct cpuid_regs r; + int i; + + ASSERT_EQ(write_file_at(AT_FDCWD, CPUID_OVERRIDE_PATH, self->table), 0); + + for (i = 0; i < NO_RESCHED_ROUNDS; i++) { + struct child_ctx ctx = { .stop = 0 }; + + spawn_cpuid_child(_metadata, self, &ctx); + collect_cpuid_child(_metadata, self, &ctx, &r); + ASSERT_EQ(r.edx, self->host.edx & ~self->bit) + TH_LOG("round %d", i); + } +} + TEST_HARNESS_MAIN -- 2.43.0 _______________________________________________ Devel mailing list Devel@openvz.org https://lists.openvz.org/mailman/listinfo/devel