From: Sean Christopherson <seanjc@google.com>
To: Sebastian Ott <sebott@redhat.com>
Cc: Zenghui Yu <zenghui.yu@linux.dev>,
Jiakai Xu <xujiakai2025@iscas.ac.cn>,
Shuah Khan <shuah@kernel.org>,
Andrew Jones <andrew.jones@oss.qualcomm.com>,
Anup Patel <anup@brainfault.org>,
kvm@vger.kernel.org, linux-kselftest@vger.kernel.org,
kvmarm@lists.linux.dev, Paolo Bonzini <pbonzini@redhat.com>,
Marc Zyngier <maz@kernel.org>, Oliver Upton <oupton@kernel.org>
Subject: Re: [PATCH] KVM: selftests: fix steal_time for arm64 with host page size > 4K
Date: Thu, 30 Jul 2026 11:37:59 -0700 [thread overview]
Message-ID: <amuaB-dZ2s3lI8NU@google.com> (raw)
In-Reply-To: <073cfbe1-0a27-015b-c688-53c186100fa1@redhat.com>
On Mon, Jun 29, 2026, Sebastian Ott wrote:
> On Sun, 28 Jun 2026, Zenghui Yu wrote:
>
> > On 6/22/26 10:14 PM, Sebastian Ott wrote:
> > >
> > > Fix the following failure when running with 16K host page size:
> > > ==== Test Assertion Failure ====
> > > lib/kvm_util.c:991: vm_adjust_num_guest_pages(vm->mode, npages) == npages
> > > pid=873 tid=873 errno=0 - Success
> > > 1 0x0000000000405a27: vm_mem_add at kvm_util.c:991
> > > 2 0x000000000040241f: check_steal_time_uapi at steal_time.c:223 (discriminator 7)
> > > 3 (inlined by) main at steal_time.c:539 (discriminator 7)
> > > 4 0x00007fff8b57af3b: ?? ??:0
> > > 5 0x00007fff8b57b007: ?? ??:0
> > > 6 0x0000000000402b6f: _start at ??:?
> > > Number of guest pages is not compatible with the host. Try npages=4
> > >
> > > Fixes: fc240715fc50 ("KVM: selftests: arm64: Fix steal_time test after UAPI refactoring")
> > > Reported-by: Zenghui Yu <zenghui.yu@linux.dev>
> > > Link: https://lore.kernel.org/kvmarm/7575a845-a542-4b16-b512-aec3126f97f3@linux.dev/T/#u
> > > Signed-off-by: Sebastian Ott <sebott@redhat.com>
> > > ---
> > > tools/testing/selftests/kvm/steal_time.c | 6 ++++--
> > > 1 file changed, 4 insertions(+), 2 deletions(-)
> > >
> > > diff --git a/tools/testing/selftests/kvm/steal_time.c b/tools/testing/selftests/kvm/steal_time.c
> > > index 76fcdd1fd3cb..cdb81f3ee4b2 100644
> > > --- a/tools/testing/selftests/kvm/steal_time.c
> > > +++ b/tools/testing/selftests/kvm/steal_time.c
> > > @@ -208,6 +208,7 @@ static void check_steal_time_uapi(void)
> > > {
> > > struct kvm_vm *vm;
> > > struct kvm_vcpu *vcpu;
> > > + unsigned int gpages;
> > > u64 st_ipa;
> > > int ret;
> > >
> > > @@ -220,8 +221,9 @@ static void check_steal_time_uapi(void)
> > > };
> > >
> > > vcpu_ioctl(vcpu, KVM_HAS_DEVICE_ATTR, &dev);
> > > - vm_userspace_mem_region_add(vm, VM_MEM_SRC_ANONYMOUS, ST_GPA_BASE, 1, 1, 0);
> > > - virt_map(vm, ST_GPA_BASE, ST_GPA_BASE, 1);
> > > + gpages = vm_calc_num_guest_pages(VM_MODE_DEFAULT, 1);
> >
> > Would vm_calc_num_guest_pages(VM_MODE_DEFAULT, STEAL_TIME_SIZE) be better
> > to describe the number of pages we want to add?
>
> Hm, I don't think we care. This is just for the uapi checker - the vm/vcpu
> doesn't even run..
Even though we don't truly care, we can "fix" that and dedup code at the same
time. E.g.
diff --git a/tools/testing/selftests/kvm/steal_time.c b/tools/testing/selftests/kvm/steal_time.c
index bc3c62b72c58..c0256d4c4b09 100644
--- a/tools/testing/selftests/kvm/steal_time.c
+++ b/tools/testing/selftests/kvm/steal_time.c
@@ -27,6 +27,9 @@
static void *st_gva[NR_VCPUS];
static u64 guest_stolen_time[NR_VCPUS];
+static struct kvm_vm *vm_create_steal_time(u32 nr_vcpus, void *guest_code,
+ struct kvm_vcpu *vcpus[]);
+
#if defined(__x86_64__)
/* steal_time must have 64-byte alignment */
@@ -210,17 +213,14 @@ static void check_steal_time_uapi(void)
u64 st_ipa;
int ret;
- vm = vm_create_with_one_vcpu(&vcpu, NULL);
-
struct kvm_device_attr dev = {
.group = KVM_ARM_VCPU_PVTIME_CTRL,
.attr = KVM_ARM_VCPU_PVTIME_IPA,
.addr = (u64)&st_ipa,
};
+ vm = vm_create_steal_time(1, NULL, &vcpu);
vcpu_ioctl(vcpu, KVM_HAS_DEVICE_ATTR, &dev);
- vm_userspace_mem_region_add(vm, VM_MEM_SRC_ANONYMOUS, ST_GPA_BASE, 1, 1, 0);
- virt_map(vm, ST_GPA_BASE, ST_GPA_BASE, 1);
st_ipa = (ulong)ST_GPA_BASE | 1;
ret = __vcpu_ioctl(vcpu, KVM_SET_DEVICE_ATTR, &dev);
@@ -500,13 +500,26 @@ static void run_vcpu(struct kvm_vcpu *vcpu)
}
}
+static struct kvm_vm *vm_create_steal_time(u32 nr_vcpus, void *guest_code,
+ struct kvm_vcpu *vcpus[])
+{
+ unsigned int gpages;
+ struct kvm_vm *vm;
+
+ vm = vm_create_with_vcpus(NR_VCPUS, guest_code, vcpus);
+ gpages = vm_calc_num_guest_pages(VM_MODE_DEFAULT, STEAL_TIME_SIZE * nr_vcpus);
+ vm_userspace_mem_region_add(vm, VM_MEM_SRC_ANONYMOUS, ST_GPA_BASE, 1, gpages, 0);
+ virt_map(vm, ST_GPA_BASE, ST_GPA_BASE, gpages);
+
+ return vm;
+}
+
int main(int ac, char **av)
{
struct kvm_vcpu *vcpus[NR_VCPUS];
struct kvm_vm *vm;
pthread_t thread;
cpu_set_t cpuset;
- unsigned int gpages;
long stolen_time;
long run_delay;
bool verbose;
@@ -518,10 +531,7 @@ int main(int ac, char **av)
cpu = pin_self_to_any_cpu();
/* Create a VM and an identity mapped memslot for the steal time structure */
- vm = vm_create_with_vcpus(NR_VCPUS, guest_code, vcpus);
- gpages = vm_calc_num_guest_pages(VM_MODE_DEFAULT, STEAL_TIME_SIZE * NR_VCPUS);
- vm_userspace_mem_region_add(vm, VM_MEM_SRC_ANONYMOUS, ST_GPA_BASE, 1, gpages, 0);
- virt_map(vm, ST_GPA_BASE, ST_GPA_BASE, gpages);
+ vm = vm_create_steal_time(NR_VCPUS, guest_code, vcpus);
ksft_print_header();
TEST_REQUIRE(is_steal_time_supported(vcpus[0]));
prev parent reply other threads:[~2026-07-30 18:38 UTC|newest]
Thread overview: 6+ messages / expand[flat|nested] mbox.gz Atom feed top
[not found] <20260504112808.21276-1-sebott@redhat.com>
2026-06-22 4:02 ` [PATCH] KVM: selftests: fix steal_time for arm64 Zenghui Yu
2026-06-22 14:14 ` [PATCH] KVM: selftests: fix steal_time for arm64 with host page size > 4K Sebastian Ott
2026-06-28 15:32 ` Zenghui Yu
2026-06-28 15:44 ` Zenghui Yu
2026-06-29 12:04 ` Sebastian Ott
2026-07-30 18:37 ` Sean Christopherson [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=amuaB-dZ2s3lI8NU@google.com \
--to=seanjc@google.com \
--cc=andrew.jones@oss.qualcomm.com \
--cc=anup@brainfault.org \
--cc=kvm@vger.kernel.org \
--cc=kvmarm@lists.linux.dev \
--cc=linux-kselftest@vger.kernel.org \
--cc=maz@kernel.org \
--cc=oupton@kernel.org \
--cc=pbonzini@redhat.com \
--cc=sebott@redhat.com \
--cc=shuah@kernel.org \
--cc=xujiakai2025@iscas.ac.cn \
--cc=zenghui.yu@linux.dev \
/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