From: Dongli Zhang <dongli.zhang@oracle.com>
To: kvm@vger.kernel.org, kvmarm@lists.linux.dev,
loongarch@lists.linux.dev, kvm-riscv@lists.infradead.org,
linux-kselftest@vger.kernel.org
Cc: maz@kernel.org, oupton@kernel.org, fuad.tabba@linux.dev,
joey.gouly@arm.com, seiden@linux.ibm.com, suzuki.poulose@arm.com,
yuzenghui@huawei.com, zhaotianrui@loongson.cn,
maobibo@loongson.cn, chenhuacai@kernel.org, anup@brainfault.org,
atish.patra@linux.dev, seanjc@google.com, pbonzini@redhat.com,
shuah@kernel.org, dwmw2@infradead.org, joe.jin@oracle.com
Subject: [PATCH v2 4/4] KVM: selftests: Add arm64 coverage for steal time pid changes
Date: Fri, 4 Sep 2026 17:55:26 +0000 [thread overview]
Message-ID: <20260904175550.430266-5-dongli.zhang@oracle.com> (raw)
In-Reply-To: <20260904175550.430266-1-dongli.zhang@oracle.com>
The previous patch added the common steal_time_change_pid test with x86
support. Add the arm64 support so the same test also covers arm64.
Use KVM_ARM_VCPU_PVTIME_IPA to enable the steal time shared page from
userspace, and use the PV_TIME_ST SMCCC call in the guest to retrieve and
read that page.
Assisted-by: Codex:GPT-5.5
Signed-off-by: Dongli Zhang <dongli.zhang@oracle.com>
---
As I have access to only x86 and arm64 KVM hosts, I created and validated
the selftest on those two architectures only.
tools/testing/selftests/kvm/Makefile.kvm | 1 +
.../selftests/kvm/steal_time_change_pid.c | 54 +++++++++++++++++++
2 files changed, 55 insertions(+)
diff --git a/tools/testing/selftests/kvm/Makefile.kvm b/tools/testing/selftests/kvm/Makefile.kvm
index 036c28849f84..1de13c0017e4 100644
--- a/tools/testing/selftests/kvm/Makefile.kvm
+++ b/tools/testing/selftests/kvm/Makefile.kvm
@@ -205,6 +205,7 @@ TEST_GEN_PROGS_arm64 += guest_memfd_test
TEST_GEN_PROGS_arm64 += mmu_stress_test
TEST_GEN_PROGS_arm64 += rseq_test
TEST_GEN_PROGS_arm64 += steal_time
+TEST_GEN_PROGS_arm64 += steal_time_change_pid
TEST_GEN_PROGS_s390 = $(TEST_GEN_PROGS_COMMON)
TEST_GEN_PROGS_s390 += s390/memop
diff --git a/tools/testing/selftests/kvm/steal_time_change_pid.c b/tools/testing/selftests/kvm/steal_time_change_pid.c
index 3c39594db398..12d4927d1c01 100644
--- a/tools/testing/selftests/kvm/steal_time_change_pid.c
+++ b/tools/testing/selftests/kvm/steal_time_change_pid.c
@@ -46,6 +46,60 @@ static void steal_time_enable(struct kvm_vcpu *vcpu)
(ulong)st_gva | KVM_MSR_ENABLED);
}
+#elif defined(__aarch64__)
+
+#define STEAL_TIME_SIZE ((sizeof(struct st_time) + 63) & ~63)
+
+#define PV_TIME_ST 0xc5000021
+
+struct st_time {
+ u32 rev;
+ u32 attr;
+ u64 st_time;
+};
+
+static void guest_code(void)
+{
+ struct arm_smccc_res res;
+ struct st_time *st;
+
+ do_smccc(PV_TIME_ST, 0, 0, 0, 0, 0, 0, 0, &res);
+ GUEST_ASSERT_NE(res.a0, -1);
+ GUEST_ASSERT_EQ(res.a0, (ulong)st_gva);
+
+ st = (struct st_time *)res.a0;
+ WRITE_ONCE(guest_stolen_time, READ_ONCE(st->st_time));
+ GUEST_SYNC(0);
+
+ WRITE_ONCE(guest_stolen_time, READ_ONCE(st->st_time));
+ GUEST_SYNC(1);
+
+ WRITE_ONCE(guest_stolen_time, READ_ONCE(st->st_time));
+ GUEST_DONE();
+}
+
+static bool steal_time_supported(struct kvm_vcpu *vcpu)
+{
+ struct kvm_device_attr dev = {
+ .group = KVM_ARM_VCPU_PVTIME_CTRL,
+ .attr = KVM_ARM_VCPU_PVTIME_IPA,
+ };
+
+ return !__vcpu_ioctl(vcpu, KVM_HAS_DEVICE_ATTR, &dev);
+}
+
+static void steal_time_enable(struct kvm_vcpu *vcpu)
+{
+ u64 st_ipa = (ulong)st_gva;
+ struct kvm_device_attr dev = {
+ .group = KVM_ARM_VCPU_PVTIME_CTRL,
+ .attr = KVM_ARM_VCPU_PVTIME_IPA,
+ .addr = (u64)&st_ipa,
+ };
+
+ vcpu_ioctl(vcpu, KVM_SET_DEVICE_ATTR, &dev);
+}
+
#else
#error "steal_time_change_pid is not implemented on this architecture"
#endif
--
2.43.7
prev parent reply other threads:[~2026-09-04 17:56 UTC|newest]
Thread overview: 9+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-09-04 17:55 [PATCH v2 0/4] KVM: Reset steal time accounting on vCPU pid change Dongli Zhang
2026-09-04 17:55 ` [PATCH v2 1/4] KVM: Move last_steal to common struct kvm_vcpu Dongli Zhang
2026-09-04 18:07 ` sashiko-bot
2026-09-04 20:22 ` Dongli Zhang
2026-09-04 17:55 ` [PATCH v2 2/4] KVM: Reset last_steal on vCPU pid change Dongli Zhang
2026-09-04 17:55 ` [PATCH v2 3/4] KVM: selftests: Test steal time across vCPU pid changes on x86 Dongli Zhang
2026-09-04 18:11 ` sashiko-bot
2026-09-04 20:27 ` Dongli Zhang
2026-09-04 17:55 ` Dongli Zhang [this message]
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20260904175550.430266-5-dongli.zhang@oracle.com \
--to=dongli.zhang@oracle.com \
--cc=anup@brainfault.org \
--cc=atish.patra@linux.dev \
--cc=chenhuacai@kernel.org \
--cc=dwmw2@infradead.org \
--cc=fuad.tabba@linux.dev \
--cc=joe.jin@oracle.com \
--cc=joey.gouly@arm.com \
--cc=kvm-riscv@lists.infradead.org \
--cc=kvm@vger.kernel.org \
--cc=kvmarm@lists.linux.dev \
--cc=linux-kselftest@vger.kernel.org \
--cc=loongarch@lists.linux.dev \
--cc=maobibo@loongson.cn \
--cc=maz@kernel.org \
--cc=oupton@kernel.org \
--cc=pbonzini@redhat.com \
--cc=seanjc@google.com \
--cc=seiden@linux.ibm.com \
--cc=shuah@kernel.org \
--cc=suzuki.poulose@arm.com \
--cc=yuzenghui@huawei.com \
--cc=zhaotianrui@loongson.cn \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox