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 129A28017D for ; Tue, 6 Oct 2026 22:56:00 +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 696MsoE3028702; Wed, 7 Oct 2026 01:54:51 +0300 DKIM-Filter: OpenDKIM Filter v2.11.0 mail.openvz.org 696MsoE3028702 Authentication-Results: mail.openvz.org; dkim=fail reason="signature verification failed" (2048-bit key) header.d=virtuozzo.com header.i=@virtuozzo.com header.b="uPnzOwTF" Received: from mail-wr1-f69.google.com (mail-wr1-f69.google.com [209.85.221.69]) by mail.openvz.org (8.14.4/8.14.4) with ESMTP id 696MscLA028665 (version=TLSv1/SSLv3 cipher=AES128-GCM-SHA256 bits=128 verify=FAIL) for ; Wed, 7 Oct 2026 01:54:38 +0300 DKIM-Filter: OpenDKIM Filter v2.11.0 mail.openvz.org 696MscLA028665 Received: by mail-wr1-f69.google.com with SMTP id ffacd0b85a97d-48c511d9e97so1837095f8f.0 for ; Tue, 06 Oct 2026 15:54:38 -0700 (PDT) X-Forwarded-Encrypted: i=2; AKwUvBxPJ5ROubm8z3U/xF7Y/JWTV2aBwiEtRQxKaEkDb3+sVINDgWD3CotZYuz0XcXcg/1CRpDvWA==@openvz.org X-Gm-Message-State: AFq9FYJMAwS99Dk0wrL4SjOk3Rr4R0kqsx9Rx8yY6la4DlfQtIUKLzZb YQcAin/2XrL638ft5ZL2bFfqjguNwIlg8gukeRPfY+zMfnUzlpbYOpG2r5kVyMNQkyZHUEP26N+ vtS9igIQF7pfQNgyskRQvKcWYmb2q3c2pGfDRsqDL/6YSaxriBeqZhg== X-Gm-Gg: AYBFou2o+d7JLjfDiIebR3a08T1QzkqNMgEFpvE2FB6QEI2gYpKdfkhDau3CdWTmoN0 keno6tXPk6Nk1Kzwv1iWEwBZq4G+ViqewcAhVkRAOxxtcN2OST8WEj0Q9u9yKrBKiiJPET1/rLs X9TgEJaVAVMll1IrUHO7axhz7lRBI+D8xe3qA8nyk2O0q6/maU4qfxSRJ0+OASEeP6JsMGFxOOS QYRpjBTSKTmV5PbbWSanAS48Cj07Wihfe9Kj+DwLU+opi5TBSD3My2bUWVS2+9uKel5h8yTLftU gz9JVaJaaj8dcq70chLxWjOOOBJIh6SqOMusFODsYXojFahzV9AM5TlMrv7W/2wylEi0i7zvUWu LLVlwTYeCC7425MSJ X-Received: by 2002:adf:e191:0:b0:48b:f93:3b87 with SMTP id ffacd0b85a97d-48c7276f1b1mr1093094f8f.30.1791327278433; Tue, 06 Oct 2026 15:54:38 -0700 (PDT) X-Received: by 2002:adf:e191:0:b0:48b:f93:3b87 with SMTP id ffacd0b85a97d-48c7276f1b1mr1093072f8f.30.1791327277885; Tue, 06 Oct 2026 15:54:37 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1791327277; cv=none; d=google.com; s=arc-20260327; b=fhOVWEvpsamklsYQDrl2amoMAtY/Ml8LPpScyG0YTe1rLBMwKxAQIV5qYdHnCHmJE5 BCwPi+DeEfdYwZ3yzTWXlUYW6qxWi3EdRiwHry7D5hg7QZKnA266qnGUKDdIzt2ouuCL XQUa+e6PAMVPbgg3b56eACRlNIjzQ63Ho4B8XxgFQ9Qs0kZBJqHAhwguO3gftaN4+i+F Z45zNvjIS9x6YJCYp7QSt+tZ2afOCQJRjBoCzXKgvPM++wq4vATZiutZsZ4lRGb/TU2+ H/4jozshRaE3hmbnTZpZgcuqhIzdyHwUg9zxW64vJE5tqtDwpSZFI3qeA2N3JRmvtaJZ NhtQ== 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=bmZJtFwGtkcXZYC4NIww3uuRcvWZ9jRHPFkG5TJs6zY=; fh=bRkZfFa6377EgOVW8zBDri2gGIQqe/ZeiH+ijEM/ROI=; b=h0gZYKZCWAzeXrlzGV+qLqPygArnilIlXLaSkBGzBVTMPNPV0UyVxEwrTNIIAZ7HSM vWJ8rWbFBMvTmoAZGZrnVN5hmHxVPfmXBas6VmK+r9GyGqynGDhqSQH2pAt4ONjJRYyl /VegCENfkTELg8TTQpay8iv8fTkY3XHSSKW6h843LQE2vpLCHzTshpfwUeRa4aHtM+Sy 7wunqKCBeCeW+3coFOcKtCyZbSG/vmwFZy1ovC3oZkZbKLjFQdR90c4eNtGPrZd9wL7c HNFHXuXCjFViBjIPfjatdnU3pGeapZw0GdamA13CiU/ZfaZ88v4Mq8KYRN4H3TV5rA/t c4zA==; dara=google.com ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@virtuozzo.com header.s=relay header.b=uPnzOwTF; 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 ffacd0b85a97d-48c724990cbsi1554503f8f.292.2026.10.06.15.54.37 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 06 Oct 2026 15:54:37 -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=uPnzOwTF; 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=bmZJtFwGtkcXZYC4NIww3uuRcvWZ9jRHPFkG5TJs6zY=; b=uPnzOwTFrE0O9bL1ncS /3PF0yzKhScxMVczrwQJBRKu4ce9PXAkyk7rkrebPpgqP74jNcELWGNIyVEhgqGFUfLOhhFG+DcnF vJN/f8D0MaYTvErGPjNy5x/2E9Ffk8KttW7fj1CfR5R3JUKhiiDmksiJdyd5iGgCKRreNebVEtnY7 SEiS3jS3sJ8/DD0JdQsPJossvUk67U9dmNkwOT7BcO5cpBDn/2GrkrUY/8jY9MJEF05xpqk0oZVFg yzyk7Lgo10oFZDmtAO/F4EqB4PFrNRXz5eUt3Vf0Ph36JDqV06Uf4x7BpgR/MDb+Rm31PxuJuxoi9 UiZpTMNWquDzYzQ==; 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 1xEE0C-005OA8-0h; Wed, 07 Oct 2026 00:54:27 +0200 From: Konstantin Khorenko Date: Wed, 07 Oct 2026 00:54:33 +0200 MIME-Version: 1.0 Message-Id: <20261007-b4-prep-khorenko-vstor-148656-cpuid-v5-3-652c5c9e56da@virtuozzo.com> References: <20261007-b4-prep-khorenko-vstor-148656-cpuid-v5-0-652c5c9e56da@virtuozzo.com> In-Reply-To: <20261007-b4-prep-khorenko-vstor-148656-cpuid-v5-0-652c5c9e56da@virtuozzo.com> To: Pavel Tikhomirov , Vasileios Almpanis X-Mailer: b4 0.16.0 X-Developer-Signature: v=1; a=openpgp-sha256; l=5993; i=khorenko@virtuozzo.com; h=from:subject:message-id; bh=YqelDnIEGnWIuC0/aLh8F02ojXGbDh7AoqYjSxzgC/k=; b=owEBbQKS/ZANAwAKAVGWCkf5YVwqAcsmYgBqxXwrFqnUYqXlCZQYHfXGGG5zTVBXUEi2GzFmW yi2vwtKlhKJAjMEAAEKAB0WIQRWD23IPcXT0GO9CCxRlgpH+WFcKgUCasV8KwAKCRBRlgpH+WFc Kqz/D/9slR4LA15GQFBxX1BQ5rOk0uUrDXY3vnYD3bu6XjIGp199u+FSWs0gwfpSn3+lOO8ktUE G884PEJ53aN6iaenI33lFOYmiLH0iD2b1YXfkdEJKp1uilRaMFjeRjQl3aERdnMvaug7sjAODjX 4JjAKc6mqehEZv3XgrI6SWAI4w4gfs3fn5CLeMit4YFds1WIABCMdkStyUfJQeoNMz5AXAAWGGG uuqfQMRXFUbq+fklb9ikVinwKvFKTEVJqAwqWlM37qK/Ga41hldu4mkV07z6D+DvX3Khmfdkx/s sXWzXUgqXqRO4UQkWc1aC4FyOtNBG2RbLPxKkJyzhCjE1L3r7sYYcMmKk7SzA/zy2tKXhZghRbF UwauwPVUkRPhyC6Nf/SG1xM1XpZAbksSseVrYrNviTHU9ol+7P2bnx3SQsWe9hUkaUN8ltYlqtI 3wSz2V0VTjZL8MhOA4QgmFMGlck80ZsiYYbITzKPamhlt+rkpk+EJm4H+1jmgSj0xgU6w8r/zfD ho8zC5KWNACgG59Zerm9KXC4yFRTrGryjj27Y86fsDFsAxSvRuVcieKi1NaNlutbmOFECxoPyIY WTYgausUy9yZbWTmDwI044ud/zH9Ie/umpOGdoiuTanN4n+aIr/9MzpWhDowThONUNGlz4Fx7f8 Sj3RP4h3qS77Pwg== 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 v5 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 | 83 +++++++++++++++------- 1 file changed, 57 insertions(+), 26 deletions(-) diff --git a/tools/testing/selftests/ve/ve_cpuid_override_test.c b/tools/testing/selftests/ve/ve_cpuid_override_test.c index 398f1fef5d246..f944fb5d806f6 100644 --- a/tools/testing/selftests/ve/ve_cpuid_override_test.c +++ b/tools/testing/selftests/ve/ve_cpuid_override_test.c @@ -32,6 +32,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) @@ -61,15 +62,16 @@ static int read_nvcsw(const char *status, unsigned long *nvcsw) 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. It tells the parent its context switch count first, so - * that the parent can wait for the switch out. + * 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. It tells the parent its context switch count + * first, so that the parent can wait for the switch out. */ static int cpuid_child(struct child_ctx *ctx) { @@ -80,12 +82,15 @@ static int cpuid_child(struct child_ctx *ctx) if (unshare(CLONE_NEWVE) < 0) return 21; - if (read_nvcsw("/proc/self/status", &nvcsw)) - return 22; - if (write(ctx->result_pipe[1], &nvcsw, sizeof(nvcsw)) != sizeof(nvcsw)) - return 23; - if (raise(SIGSTOP)) - return 24; + if (ctx->stop) { + if (read_nvcsw("/proc/self/status", &nvcsw)) + return 22; + if (write(ctx->result_pipe[1], &nvcsw, sizeof(nvcsw)) != + sizeof(nvcsw)) + return 23; + if (raise(SIGSTOP)) + return 24; + } do_cpuid(CPUID_LEAF, &r); @@ -193,7 +198,7 @@ static void wait_switched_out(struct __test_metadata *_metadata, pid_t pid, ASSERT_GT(nvcsw, nvcsw_before); } -/* Fork the child into the VE and return once it is off the CPU. */ +/* Fork the child into the VE; with @stop return once it is off the CPU. */ static pid_t spawn_cpuid_child(struct __test_metadata *_metadata, FIXTURE_DATA(ve_cpuid_override) * self, struct child_ctx *ctx) @@ -216,19 +221,23 @@ 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_EQ(read(ctx->result_pipe[0], &nvcsw, sizeof(nvcsw)), + (int)sizeof(nvcsw)); + wait_switched_out(_metadata, pid, nvcsw); } - ASSERT_TRUE(WIFSTOPPED(status)); - ASSERT_EQ(read(ctx->result_pipe[0], &nvcsw, sizeof(nvcsw)), - (int)sizeof(nvcsw)); - wait_switched_out(_metadata, pid, nvcsw); return pid; } @@ -257,7 +266,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; @@ -278,7 +287,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; @@ -293,4 +302,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