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 75D80802A5 for ; Wed, 7 Oct 2026 11:58:38 +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 697BvNeV004359; Wed, 7 Oct 2026 14:57:23 +0300 DKIM-Filter: OpenDKIM Filter v2.11.0 mail.openvz.org 697BvNeV004359 Authentication-Results: mail.openvz.org; dkim=fail reason="signature verification failed" (2048-bit key) header.d=virtuozzo.com header.i=@virtuozzo.com header.b="O3EjePCa" 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 697Bv9MW004324 (version=TLSv1/SSLv3 cipher=AES128-GCM-SHA256 bits=128 verify=FAIL) for ; Wed, 7 Oct 2026 14:57:09 +0300 DKIM-Filter: OpenDKIM Filter v2.11.0 mail.openvz.org 697Bv9MW004324 Received: by mail-wm1-f70.google.com with SMTP id 5b1f17b1804b1-4a17c024b89so14412535e9.1 for ; Wed, 07 Oct 2026 04:57:09 -0700 (PDT) X-Forwarded-Encrypted: i=2; AKwUvBzRxUDZ6va3seh8vaIjQTkQH13S4Saa5ZZ4aPaDx+/t++RxJgzGrDvBLF6W2xK5HaG+ViDBVQ==@openvz.org X-Gm-Message-State: AFuF++kPn4Ctc24BV6ttWSR4RAXrlGimgbdiKPGix0NpAglJU+LA9lF6 ThmI40jvq/P1zQebRG2+6zcMDAEWo5kH+BVsujYAx8eKv5TIgDntMkiSV6KXXKB7Mx0WYkQ8P2b 0ZKi3KqrF5QFFx0H/AGXKihgpu77DsulwjSbaxq7VZQC+I+zCwI4Qzg== X-Gm-Gg: AYBFou2vGHhCUGn+7WyU533eMyT0uK9XePqsEuM/Mz2uaa73cGDJVUSMUBCX11Sw/co bFAVUW9J8GLyqySh8becukQ1VAHtXIHiud3x1qc7ycjdbvqnqJ/nC8jGELfUgBXtHDLVVRpUzZ2 meoFnnjzvQyu7s/xpzERobEnHR2XJFxltlp0c9P2kpGGT81Et34Cl/21JERfo037AkDdePGspb9 virwghZhCXSqmDSK8jykdjsrAlR0BL7OwnGLPtg3Nt6d9gyGFpFOyuEaI5rOUq1rMyzuBfyJ0W1 aD90lbJcnvDLT3PSljipitdqpVHjia9LDyduK+OEaH9F+WIzWSLAkTsudteKvYNPSSJ5xysYdfS 1Iqxdci5FIVOLzIX1GA== X-Received: by 2002:a05:600c:609a:b0:4a0:2540:b46 with SMTP id 5b1f17b1804b1-4a18031130emr32288465e9.12.1791374228856; Wed, 07 Oct 2026 04:57:08 -0700 (PDT) X-Received: by 2002:a05:600c:609a:b0:4a0:2540:b46 with SMTP id 5b1f17b1804b1-4a18031130emr32287875e9.12.1791374228230; Wed, 07 Oct 2026 04:57:08 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1791374228; cv=none; d=google.com; s=arc-20260327; b=KpL3epQr1MDk1lC1HGy2zxouG8jl9+frlYNe5mLIy9G7UYPtVnAmIYM6X3YVnkspHn 9goFtYmnqF/DZYDrJlcAjdB4Eiojc3DYSZJJ36j4qJ5kHgcMhsFaxtP43a1b6Pt8SKJ3 ehIGIOcThtZm2mss4mPYdO/nxrqwWNTAhEzHY0FgqD6F7QWEBS5kWlAPDgRzJamEImYh 8cYWeLZQt4+gqjs/ZZPakuyL/eW4Eqrnq2Jd3nCBXPD+PLLJIYh3BLRb3Uhmlcnrt7Pf FI8HSGu5hIEg9wdOYAANNsFc/ereKpvEI9lGmPH1UZr0U00AmxsADR4CBz0l1LC0myS6 Wkww== 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=vRc0W9oFIpLzJILzUtNPH0ZPnpE91VUOGbhkyDSMRnA=; fh=bRkZfFa6377EgOVW8zBDri2gGIQqe/ZeiH+ijEM/ROI=; b=A7OStFRqGW13Cv8C5jLbf1hsXLGbRJAuWf9c1QmBt3IfM9gbcSWxMfKf9Eg3rnqaUy AZ1/TxrLZzQBCTwaOIBOznO3ll8TEXdrcEVNV9Fnl/X11Eh5Eledvf5bIJggcinAqD9c H+DDmzjpfYpNThD8mJuVtu9QLvVwrm6jRduueVK/IZcx2TY2HX0vrZUPj9nEF3vNNYwJ EwVOI2srH54iNOFAq5OSFnFAApyWC1PiT7IuTv1bI7isnsT0o62KV4k/WCvUOa2iCoPL p7q7j2s0FM2KNWpUkeDDqd1Lu5oxKSGMuVM3CBbq7sVdaONnygvjosE7GxItyB2zjK9E wOsw==; dara=google.com ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@virtuozzo.com header.s=relay header.b=O3EjePCa; 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-4a1816e10f2si31496535e9.6.2026.10.07.04.57.08 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 07 Oct 2026 04:57:08 -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=O3EjePCa; 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=vRc0W9oFIpLzJILzUtNPH0ZPnpE91VUOGbhkyDSMRnA=; b=O3EjePCaLlUedGx9YBy VRap9EG+XKIUSnQMKTQiZ5QeXqeaSKHMmFbsGYs39sJXTbc9ouzNfnacligevwWanFTII3p/TWalD /9j8RuCOnlPHuJlu6NiJhH0VRe4lZO/3T5b+mrnTPKAtjdPZH9pTMPX10xoi6wjDvXW+QmlM/7PZN Q4off7xrhm2f3DS1dXbr7C1KLaboyCKzEpHPjsEm4/Bp2Ql8zOGfD2A3/qGu2dE7pP6fdmLI5+k3Q AQz9+KA+bwmZhOqqmf/2orDre0+bkrYmjHJjArJwmkIaLrX5ZCbuOfcFB3Mq+mm9+QLbuuhLkdlNC WlRMMvVO3Y5XpEg==; 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 1xEQDR-002m3X-2D; Wed, 07 Oct 2026 13:57:07 +0200 From: Konstantin Khorenko Date: Wed, 07 Oct 2026 13:57:04 +0200 MIME-Version: 1.0 Message-Id: <20261007-b4-prep-khorenko-vstor-148656-cpuid-v6-3-a8eb906e69b8@virtuozzo.com> References: <20261007-b4-prep-khorenko-vstor-148656-cpuid-v6-0-a8eb906e69b8@virtuozzo.com> In-Reply-To: <20261007-b4-prep-khorenko-vstor-148656-cpuid-v6-0-a8eb906e69b8@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=I2HW3FgkarYP6Ee061VyhvXetof3R6Vf8tuBTyC3mPU=; b=owEBbQKS/ZANAwAKAVGWCkf5YVwqAcsmYgBqxjOSRiHU3k6o/ced8EmFEWK6MlvwsjjirI+2B yurGEUeUESJAjMEAAEKAB0WIQRWD23IPcXT0GO9CCxRlgpH+WFcKgUCasYzkgAKCRBRlgpH+WFc KouTEACV5jijJr9kNwCr+sX3LLI9989paWArJ/JF2waA/3cmLVsVz/6842jiFPfn/FhvPUe1Sjj hoF4W+EAQ9NgPNyf9nLQ+YD4EtAn/jaGQLcwVsYHfTBxRZhPleJA21D6ngRIa5crU0vud/rW8kS 2I2Jp9HiQOod1ZblIekNLAsFE4A4qA6t5uYsKZxGP/f23xt7rLp7rH9er+0xhD8SujT1429azkH Lsnry2HBgOATEkCWC8KyZAizo6u4UKQe/l5aenYZvT/RpOlDCD21QjLZp+0gD60KkphRnLNIO8E 6fFvX/SBrAwKLzx1rwWf0HSkMZJhx4ASH5XGsh0VmcKdO4ZjicxBZ0fInub3EE0AbLG27XTvECX 24VBLsjj8mqqMNU8ta4+MpsbZ+Ndkx79t3gdz0FUgMAa43Sf3Zeqe49oAMpNVeeBv1pR09JpVsj bfLXUG0QIMmnYZq8R47T5kxvpPog9YKec/vU7S7Ju+Zwin6zkJN5UDlA4ksdhzZYq+CokfoQx4m PuR15kErPmMhZ+r9eKAuZJs622EY1LCRo4g3D5Of2PrLqpJPOA1wWSn0j3BDx3TLf7yxZqhA+aN NFKeQbJhEKamDc4oUeFYEUzPfsM5Uwo1aKwolLosoUj1FluM++fh0lE4tdkY+B1JobLKB9dml+n kz4mbMxnucmW2HQ== 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 v6 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 a56e0c7213fb9..f6a6325e4b42d 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); @@ -195,7 +200,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) @@ -218,19 +223,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; } @@ -259,7 +268,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; @@ -280,7 +289,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; @@ -295,4 +304,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