* [PATCH v3 0/4] KVM: arm64: selftests: arch_timer_edge_cases fixes
@ 2025-06-05 10:36 Sebastian Ott
2025-06-05 10:36 ` [PATCH v3 1/4] KVM: arm64: selftests: fix help text for arch_timer_edge_cases Sebastian Ott
` (5 more replies)
0 siblings, 6 replies; 8+ messages in thread
From: Sebastian Ott @ 2025-06-05 10:36 UTC (permalink / raw)
To: Marc Zyngier, Oliver Upton
Cc: Colton Lewis, Ricardo Koller, Joey Gouly, Suzuki K Poulose,
Zenghui Yu, Shuah Khan, linux-arm-kernel, kvmarm, linux-kernel,
linux-kselftest, Sebastian Ott
Some small fixes for arch_timer_edge_cases that I stumbled upon
while debugging failures for this selftest on ampere-one.
Changes since v1:
* determine effective counter width based on suggestions from Marc
Changes since v2:
* new patch to fix xval initialization
I've done tests with this on various machines - no issues during
several hundreds of test runs.
v1: https://lore.kernel.org/kvmarm/20250509143312.34224-1-sebott@redhat.com/
v2: https://lore.kernel.org/kvmarm/20250527142434.25209-1-sebott@redhat.com/
Sebastian Ott (4):
KVM: arm64: selftests: fix help text for arch_timer_edge_cases
KVM: arm64: selftests: fix thread migration in arch_timer_edge_cases
KVM: arm64: selftests: arch_timer_edge_cases - fix xval init
KVM: arm64: selftests: arch_timer_edge_cases - determine effective counter width
.../kvm/arm64/arch_timer_edge_cases.c | 39 ++++++++++++-------
1 file changed, 25 insertions(+), 14 deletions(-)
base-commit: 0ff41df1cb268fc69e703a08a57ee14ae967d0ca
--
2.49.0
^ permalink raw reply [flat|nested] 8+ messages in thread
* [PATCH v3 1/4] KVM: arm64: selftests: fix help text for arch_timer_edge_cases
2025-06-05 10:36 [PATCH v3 0/4] KVM: arm64: selftests: arch_timer_edge_cases fixes Sebastian Ott
@ 2025-06-05 10:36 ` Sebastian Ott
2025-06-05 10:36 ` [PATCH v3 2/4] KVM: arm64: selftests: fix thread migration in arch_timer_edge_cases Sebastian Ott
` (4 subsequent siblings)
5 siblings, 0 replies; 8+ messages in thread
From: Sebastian Ott @ 2025-06-05 10:36 UTC (permalink / raw)
To: Marc Zyngier, Oliver Upton
Cc: Colton Lewis, Ricardo Koller, Joey Gouly, Suzuki K Poulose,
Zenghui Yu, Shuah Khan, linux-arm-kernel, kvmarm, linux-kernel,
linux-kselftest, Sebastian Ott
Fix the help text for arch_timer_edge_cases to show the correct
option for setting the wait time.
Signed-off-by: Sebastian Ott <sebott@redhat.com>
---
tools/testing/selftests/kvm/arm64/arch_timer_edge_cases.c | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/tools/testing/selftests/kvm/arm64/arch_timer_edge_cases.c b/tools/testing/selftests/kvm/arm64/arch_timer_edge_cases.c
index a36a7e2db434..c4716e0c1438 100644
--- a/tools/testing/selftests/kvm/arm64/arch_timer_edge_cases.c
+++ b/tools/testing/selftests/kvm/arm64/arch_timer_edge_cases.c
@@ -986,7 +986,7 @@ static void test_print_help(char *name)
pr_info("\t-b: Test both physical and virtual timers (default: true)\n");
pr_info("\t-l: Delta (in ms) used for long wait time test (default: %u)\n",
LONG_WAIT_TEST_MS);
- pr_info("\t-l: Delta (in ms) used for wait times (default: %u)\n",
+ pr_info("\t-w: Delta (in ms) used for wait times (default: %u)\n",
WAIT_TEST_MS);
pr_info("\t-p: Test physical timer (default: true)\n");
pr_info("\t-v: Test virtual timer (default: true)\n");
--
2.49.0
^ permalink raw reply related [flat|nested] 8+ messages in thread
* [PATCH v3 2/4] KVM: arm64: selftests: fix thread migration in arch_timer_edge_cases
2025-06-05 10:36 [PATCH v3 0/4] KVM: arm64: selftests: arch_timer_edge_cases fixes Sebastian Ott
2025-06-05 10:36 ` [PATCH v3 1/4] KVM: arm64: selftests: fix help text for arch_timer_edge_cases Sebastian Ott
@ 2025-06-05 10:36 ` Sebastian Ott
2025-06-05 10:36 ` [PATCH v3 3/4] KVM: arm64: selftests: arch_timer_edge_cases - fix xval init Sebastian Ott
` (3 subsequent siblings)
5 siblings, 0 replies; 8+ messages in thread
From: Sebastian Ott @ 2025-06-05 10:36 UTC (permalink / raw)
To: Marc Zyngier, Oliver Upton
Cc: Colton Lewis, Ricardo Koller, Joey Gouly, Suzuki K Poulose,
Zenghui Yu, Shuah Khan, linux-arm-kernel, kvmarm, linux-kernel,
linux-kselftest, Sebastian Ott
arch_timer_edge_cases tries to migrate itself across host cpus. Before
the first test it migrates to cpu 0 by setting up an affinity mask with
only bit 0 set. After that it looks for the next possible cpu in the
current affinity mask which still has only bit 0 set. So there is no
migration at all.
Fix this by reading the default mask at start and use this to find
the next cpu in each iteration.
Signed-off-by: Sebastian Ott <sebott@redhat.com>
---
tools/testing/selftests/kvm/arm64/arch_timer_edge_cases.c | 8 +++++---
1 file changed, 5 insertions(+), 3 deletions(-)
diff --git a/tools/testing/selftests/kvm/arm64/arch_timer_edge_cases.c b/tools/testing/selftests/kvm/arm64/arch_timer_edge_cases.c
index c4716e0c1438..a813b4c6c817 100644
--- a/tools/testing/selftests/kvm/arm64/arch_timer_edge_cases.c
+++ b/tools/testing/selftests/kvm/arm64/arch_timer_edge_cases.c
@@ -849,17 +849,17 @@ static void guest_code(enum arch_timer timer)
GUEST_DONE();
}
+static cpu_set_t default_cpuset;
+
static uint32_t next_pcpu(void)
{
uint32_t max = get_nprocs();
uint32_t cur = sched_getcpu();
uint32_t next = cur;
- cpu_set_t cpuset;
+ cpu_set_t cpuset = default_cpuset;
TEST_ASSERT(max > 1, "Need at least two physical cpus");
- sched_getaffinity(0, sizeof(cpuset), &cpuset);
-
do {
next = (next + 1) % CPU_SETSIZE;
} while (!CPU_ISSET(next, &cpuset));
@@ -1046,6 +1046,8 @@ int main(int argc, char *argv[])
if (!parse_args(argc, argv))
exit(KSFT_SKIP);
+ sched_getaffinity(0, sizeof(default_cpuset), &default_cpuset);
+
if (test_args.test_virtual) {
test_vm_create(&vm, &vcpu, VIRTUAL);
test_run(vm, vcpu);
--
2.49.0
^ permalink raw reply related [flat|nested] 8+ messages in thread
* [PATCH v3 3/4] KVM: arm64: selftests: arch_timer_edge_cases - fix xval init
2025-06-05 10:36 [PATCH v3 0/4] KVM: arm64: selftests: arch_timer_edge_cases fixes Sebastian Ott
2025-06-05 10:36 ` [PATCH v3 1/4] KVM: arm64: selftests: fix help text for arch_timer_edge_cases Sebastian Ott
2025-06-05 10:36 ` [PATCH v3 2/4] KVM: arm64: selftests: fix thread migration in arch_timer_edge_cases Sebastian Ott
@ 2025-06-05 10:36 ` Sebastian Ott
2025-06-05 10:36 ` [PATCH v3 4/4] KVM: arm64: selftests: arch_timer_edge_cases - determine effective counter width Sebastian Ott
` (2 subsequent siblings)
5 siblings, 0 replies; 8+ messages in thread
From: Sebastian Ott @ 2025-06-05 10:36 UTC (permalink / raw)
To: Marc Zyngier, Oliver Upton
Cc: Colton Lewis, Ricardo Koller, Joey Gouly, Suzuki K Poulose,
Zenghui Yu, Shuah Khan, linux-arm-kernel, kvmarm, linux-kernel,
linux-kselftest, Sebastian Ott
arch_timer_edge_cases hits the following assertion in < 10% of the test runs:
==== Test Assertion Failure ====
arm64/arch_timer_edge_cases.c:490: timer_get_cntct(timer) >= DEF_CNT + (timer_get_cntfrq() * (uint64_t)(delta_2_ms) / 1000)
pid=17110 tid=17110 errno=4 - Interrupted system call
1 0x0000000000404ec7: test_run at arch_timer_edge_cases.c:945
2 0x0000000000401fa3: main at arch_timer_edge_cases.c:1074
3 0x0000ffffa774b587: ?? ??:0
4 0x0000ffffa774b65f: ?? ??:0
5 0x000000000040206f: _start at ??:?
timer_get_cntct(timer) >= DEF_CNT + msec_to_cycles(delta_2_ms)
Enabling the timer without proper xval initialization in set_tval_irq()
resulted in an early interrupt during timer reprogramming. Make sure
to set the xval before setting the enable bit.
Signed-off-by: Sebastian Ott <sebott@redhat.com>
---
tools/testing/selftests/kvm/arm64/arch_timer_edge_cases.c | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/tools/testing/selftests/kvm/arm64/arch_timer_edge_cases.c b/tools/testing/selftests/kvm/arm64/arch_timer_edge_cases.c
index a813b4c6c817..be8bbedc933b 100644
--- a/tools/testing/selftests/kvm/arm64/arch_timer_edge_cases.c
+++ b/tools/testing/selftests/kvm/arm64/arch_timer_edge_cases.c
@@ -191,8 +191,8 @@ static void set_tval_irq(enum arch_timer timer, uint64_t tval_cycles,
{
atomic_set(&shared_data.handled, 0);
atomic_set(&shared_data.spurious, 0);
- timer_set_ctl(timer, ctl);
timer_set_tval(timer, tval_cycles);
+ timer_set_ctl(timer, ctl);
}
static void set_xval_irq(enum arch_timer timer, uint64_t xval, uint32_t ctl,
--
2.49.0
^ permalink raw reply related [flat|nested] 8+ messages in thread
* [PATCH v3 4/4] KVM: arm64: selftests: arch_timer_edge_cases - determine effective counter width
2025-06-05 10:36 [PATCH v3 0/4] KVM: arm64: selftests: arch_timer_edge_cases fixes Sebastian Ott
` (2 preceding siblings ...)
2025-06-05 10:36 ` [PATCH v3 3/4] KVM: arm64: selftests: arch_timer_edge_cases - fix xval init Sebastian Ott
@ 2025-06-05 10:36 ` Sebastian Ott
2025-06-05 13:33 ` [PATCH v3 0/4] KVM: arm64: selftests: arch_timer_edge_cases fixes Marc Zyngier
2025-06-09 17:26 ` Miguel Luis
5 siblings, 0 replies; 8+ messages in thread
From: Sebastian Ott @ 2025-06-05 10:36 UTC (permalink / raw)
To: Marc Zyngier, Oliver Upton
Cc: Colton Lewis, Ricardo Koller, Joey Gouly, Suzuki K Poulose,
Zenghui Yu, Shuah Khan, linux-arm-kernel, kvmarm, linux-kernel,
linux-kselftest, Sebastian Ott
arch_timer_edge_cases uses ~0 as the maximum counter value, however there's
no architectural guarantee that this is valid.
Figure out the effective counter width based on the effective frequency
like it's done by the kernel.
This also serves as a workaround for AC03_CPU_14 that led to the
following assertion failure on ampere-one machines:
==== Test Assertion Failure ====
arm64/arch_timer_edge_cases.c:169: timer_condition == istatus
pid=11236 tid=11236 errno=4 - Interrupted system call
1 0x0000000000404ce7: test_run at arch_timer_edge_cases.c:938
2 0x0000000000401ebb: main at arch_timer_edge_cases.c:1053
3 0x0000ffff9fa8625b: ?? ??:0
4 0x0000ffff9fa8633b: ?? ??:0
5 0x0000000000401fef: _start at ??:?
0x1 != 0x0 (timer_condition != istatus)
Note that the following subtest only worked since the counter initialized
with CVAL_MAX would instantly overflow (which is no longer the case):
test_set_cnt_after_cval_no_irq(timer, 0, DEF_CNT, CVAL_MAX, sm);
To fix this we could swap CVAL_MAX for 0 here but since that is already
done by test_move_counters_behind_timers() let's remove that subtest.
Link: https://lore.kernel.org/kvmarm/ac1de1d2-ef2b-d439-dc48-8615e121b07b@redhat.com
Link: https://amperecomputing.com/assets/AmpereOne_Developer_ER_v0_80_20240823_28945022f4.pdf
Signed-off-by: Sebastian Ott <sebott@redhat.com>
---
.../kvm/arm64/arch_timer_edge_cases.c | 27 ++++++++++++-------
1 file changed, 18 insertions(+), 9 deletions(-)
diff --git a/tools/testing/selftests/kvm/arm64/arch_timer_edge_cases.c b/tools/testing/selftests/kvm/arm64/arch_timer_edge_cases.c
index be8bbedc933b..b4d22b3ab7cc 100644
--- a/tools/testing/selftests/kvm/arm64/arch_timer_edge_cases.c
+++ b/tools/testing/selftests/kvm/arm64/arch_timer_edge_cases.c
@@ -22,7 +22,8 @@
#include "gic.h"
#include "vgic.h"
-static const uint64_t CVAL_MAX = ~0ULL;
+/* Depends on counter width. */
+static uint64_t CVAL_MAX;
/* tval is a signed 32-bit int. */
static const int32_t TVAL_MAX = INT32_MAX;
static const int32_t TVAL_MIN = INT32_MIN;
@@ -30,8 +31,8 @@ static const int32_t TVAL_MIN = INT32_MIN;
/* After how much time we say there is no IRQ. */
static const uint32_t TIMEOUT_NO_IRQ_US = 50000;
-/* A nice counter value to use as the starting one for most tests. */
-static const uint64_t DEF_CNT = (CVAL_MAX / 2);
+/* Counter value to use as the starting one for most tests. Set to CVAL_MAX/2 */
+static uint64_t DEF_CNT;
/* Number of runs. */
static const uint32_t NR_TEST_ITERS_DEF = 5;
@@ -732,12 +733,6 @@ static void test_move_counters_ahead_of_timers(enum arch_timer timer)
test_set_cnt_after_tval(timer, 0, tval, (uint64_t) tval + 1,
wm);
}
-
- for (i = 0; i < ARRAY_SIZE(sleep_method); i++) {
- sleep_method_t sm = sleep_method[i];
-
- test_set_cnt_after_cval_no_irq(timer, 0, DEF_CNT, CVAL_MAX, sm);
- }
}
/*
@@ -975,6 +970,8 @@ static void test_vm_create(struct kvm_vm **vm, struct kvm_vcpu **vcpu,
test_init_timer_irq(*vm, *vcpu);
vgic_v3_setup(*vm, 1, 64);
sync_global_to_guest(*vm, test_args);
+ sync_global_to_guest(*vm, CVAL_MAX);
+ sync_global_to_guest(*vm, DEF_CNT);
}
static void test_print_help(char *name)
@@ -1035,6 +1032,17 @@ static bool parse_args(int argc, char *argv[])
return false;
}
+static void set_counter_defaults(void)
+{
+ const uint64_t MIN_ROLLOVER_SECS = 40ULL * 365 * 24 * 3600;
+ uint64_t freq = read_sysreg(CNTFRQ_EL0);
+ uint64_t width = ilog2(MIN_ROLLOVER_SECS * freq);
+
+ width = clamp(width, 56, 64);
+ CVAL_MAX = GENMASK_ULL(width - 1, 0);
+ DEF_CNT = CVAL_MAX / 2;
+}
+
int main(int argc, char *argv[])
{
struct kvm_vcpu *vcpu;
@@ -1047,6 +1055,7 @@ int main(int argc, char *argv[])
exit(KSFT_SKIP);
sched_getaffinity(0, sizeof(default_cpuset), &default_cpuset);
+ set_counter_defaults();
if (test_args.test_virtual) {
test_vm_create(&vm, &vcpu, VIRTUAL);
--
2.49.0
^ permalink raw reply related [flat|nested] 8+ messages in thread
* Re: [PATCH v3 0/4] KVM: arm64: selftests: arch_timer_edge_cases fixes
2025-06-05 10:36 [PATCH v3 0/4] KVM: arm64: selftests: arch_timer_edge_cases fixes Sebastian Ott
` (3 preceding siblings ...)
2025-06-05 10:36 ` [PATCH v3 4/4] KVM: arm64: selftests: arch_timer_edge_cases - determine effective counter width Sebastian Ott
@ 2025-06-05 13:33 ` Marc Zyngier
2025-06-09 17:26 ` Miguel Luis
5 siblings, 0 replies; 8+ messages in thread
From: Marc Zyngier @ 2025-06-05 13:33 UTC (permalink / raw)
To: Oliver Upton, Sebastian Ott
Cc: Colton Lewis, Ricardo Koller, Joey Gouly, Suzuki K Poulose,
Zenghui Yu, Shuah Khan, linux-arm-kernel, kvmarm, linux-kernel,
linux-kselftest
On Thu, 05 Jun 2025 12:36:09 +0200, Sebastian Ott wrote:
> Some small fixes for arch_timer_edge_cases that I stumbled upon
> while debugging failures for this selftest on ampere-one.
>
> Changes since v1:
> * determine effective counter width based on suggestions from Marc
> Changes since v2:
> * new patch to fix xval initialization
>
> [...]
Applied to fixes, thanks!
[1/4] KVM: arm64: selftests: fix help text for arch_timer_edge_cases
commit: 9a9864fd09c7e52440c05e70609bf5ee8da425d0
[2/4] KVM: arm64: selftests: fix thread migration in arch_timer_edge_cases
commit: 050632ae6571d0f148fa0d4b90b6409a12645461
[3/4] KVM: arm64: selftests: arch_timer_edge_cases - fix xval init
commit: 05ce38d489dbc96eb1dd700b287f949cb8cc0610
[4/4] KVM: arm64: selftests: arch_timer_edge_cases - determine effective counter width
commit: fad4cf944839da7f5c3376243aa353295c88f588
Cheers,
M.
--
Without deviation from the norm, progress is not possible.
^ permalink raw reply [flat|nested] 8+ messages in thread
* Re: [PATCH v3 0/4] KVM: arm64: selftests: arch_timer_edge_cases fixes
2025-06-05 10:36 [PATCH v3 0/4] KVM: arm64: selftests: arch_timer_edge_cases fixes Sebastian Ott
` (4 preceding siblings ...)
2025-06-05 13:33 ` [PATCH v3 0/4] KVM: arm64: selftests: arch_timer_edge_cases fixes Marc Zyngier
@ 2025-06-09 17:26 ` Miguel Luis
2025-06-10 13:50 ` Sebastian Ott
5 siblings, 1 reply; 8+ messages in thread
From: Miguel Luis @ 2025-06-09 17:26 UTC (permalink / raw)
To: Sebastian Ott
Cc: Marc Zyngier, Oliver Upton, Colton Lewis, Ricardo Koller,
Joey Gouly, Suzuki K Poulose, Zenghui Yu, Shuah Khan,
linux-arm-kernel@lists.infradead.org, kvmarm@lists.linux.dev,
linux-kernel@vger.kernel.org, linux-kselftest@vger.kernel.org
Hi Sebastian,
Thanks in advance.
> On 5 Jun 2025, at 10:36, Sebastian Ott <sebott@redhat.com> wrote:
>
> Some small fixes for arch_timer_edge_cases that I stumbled upon
> while debugging failures for this selftest on ampere-one.
>
I’ve tested this test under three circumstances:
1) Original (!HAS_EL2 && !HAS_EL2_E2H0)
2) HAS_EL2 && HAS_EL2_E2H0
3) HAS_EL2 && !HAS_EL2_E2H0
Tests 1) and 2) returned in approx. the same amount of real time (about 12s) although 3) doesn’t
seem to return at all.
I’ve tested it on ampere-one.
Miguel
> Changes since v1:
> * determine effective counter width based on suggestions from Marc
> Changes since v2:
> * new patch to fix xval initialization
>
> I've done tests with this on various machines - no issues during
> several hundreds of test runs.
>
> v1: https://lore.kernel.org/kvmarm/20250509143312.34224-1-sebott@redhat.com/
> v2: https://lore.kernel.org/kvmarm/20250527142434.25209-1-sebott@redhat.com/
>
> Sebastian Ott (4):
> KVM: arm64: selftests: fix help text for arch_timer_edge_cases
> KVM: arm64: selftests: fix thread migration in arch_timer_edge_cases
> KVM: arm64: selftests: arch_timer_edge_cases - fix xval init
> KVM: arm64: selftests: arch_timer_edge_cases - determine effective counter width
>
> .../kvm/arm64/arch_timer_edge_cases.c | 39 ++++++++++++-------
> 1 file changed, 25 insertions(+), 14 deletions(-)
>
>
> base-commit: 0ff41df1cb268fc69e703a08a57ee14ae967d0ca
> --
> 2.49.0
>
>
^ permalink raw reply [flat|nested] 8+ messages in thread
* Re: [PATCH v3 0/4] KVM: arm64: selftests: arch_timer_edge_cases fixes
2025-06-09 17:26 ` Miguel Luis
@ 2025-06-10 13:50 ` Sebastian Ott
0 siblings, 0 replies; 8+ messages in thread
From: Sebastian Ott @ 2025-06-10 13:50 UTC (permalink / raw)
To: Miguel Luis
Cc: Marc Zyngier, Oliver Upton, Colton Lewis, Ricardo Koller,
Joey Gouly, Suzuki K Poulose, Zenghui Yu, Shuah Khan,
linux-arm-kernel@lists.infradead.org, kvmarm@lists.linux.dev,
linux-kernel@vger.kernel.org, linux-kselftest@vger.kernel.org
[-- Attachment #1: Type: text/plain, Size: 664 bytes --]
Hej Miguel,
On Mon, 9 Jun 2025, Miguel Luis wrote:
>> On 5 Jun 2025, at 10:36, Sebastian Ott <sebott@redhat.com> wrote:
>>
>> Some small fixes for arch_timer_edge_cases that I stumbled upon
>> while debugging failures for this selftest on ampere-one.
>>
>
> I’ve tested this test under three circumstances:
>
> 1) Original (!HAS_EL2 && !HAS_EL2_E2H0)
>
> 2) HAS_EL2 && HAS_EL2_E2H0
>
> 3) HAS_EL2 && !HAS_EL2_E2H0
>
> Tests 1) and 2) returned in approx. the same amount of real time (about 12s) although 3) doesn’t
> seem to return at all.
I've never really looked at nested stuff, I'll try to set smth up and see
if I can reproduce that..
Thanks,
Sebastian
^ permalink raw reply [flat|nested] 8+ messages in thread
end of thread, other threads:[~2025-06-10 13:50 UTC | newest]
Thread overview: 8+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2025-06-05 10:36 [PATCH v3 0/4] KVM: arm64: selftests: arch_timer_edge_cases fixes Sebastian Ott
2025-06-05 10:36 ` [PATCH v3 1/4] KVM: arm64: selftests: fix help text for arch_timer_edge_cases Sebastian Ott
2025-06-05 10:36 ` [PATCH v3 2/4] KVM: arm64: selftests: fix thread migration in arch_timer_edge_cases Sebastian Ott
2025-06-05 10:36 ` [PATCH v3 3/4] KVM: arm64: selftests: arch_timer_edge_cases - fix xval init Sebastian Ott
2025-06-05 10:36 ` [PATCH v3 4/4] KVM: arm64: selftests: arch_timer_edge_cases - determine effective counter width Sebastian Ott
2025-06-05 13:33 ` [PATCH v3 0/4] KVM: arm64: selftests: arch_timer_edge_cases fixes Marc Zyngier
2025-06-09 17:26 ` Miguel Luis
2025-06-10 13:50 ` Sebastian Ott
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).