All of lore.kernel.org
 help / color / mirror / Atom feed
From: Marc Zyngier <maz@kernel.org>
To: Oliver Upton <oupton@google.com>
Cc: kvm@vger.kernel.org, pbonzini@redhat.com, kvmarm@lists.cs.columbia.edu
Subject: Re: [PATCH v2 2/3] KVM: arm64: selftests: add arch_timer_edge_cases
Date: Thu, 17 Mar 2022 08:52:38 +0000	[thread overview]
Message-ID: <5fe2be916e1dcfe491fd3b40466d1932@kernel.org> (raw)
In-Reply-To: <YjLY5y+KObV0AR9g@google.com>

On 2022-03-17 06:44, Oliver Upton wrote:
> On Wed, Mar 16, 2022 at 09:51:26PM -0700, Ricardo Koller wrote:
>> Add an arch_timer edge-cases selftest. For now, just add some basic
>> sanity checks, and some stress conditions (like waiting for the timers
>> while re-scheduling the vcpu). The next commit will add the actual 
>> edge
>> case tests.
>> 
>> This test fails without a867e9d0cc1 "KVM: arm64: Don't miss pending
>> interrupts for suspended vCPU".
>> 
>> Reviewed-by: Reiji Watanabe <reijiw@google.com>
>> Reviewed-by: Raghavendra Rao Ananta <rananta@google.com>
>> Signed-off-by: Ricardo Koller <ricarkol@google.com>

[...]

>> +		asm volatile("wfi\n"
>> +			     "msr daifclr, #2\n"
>> +			     /* handle IRQ */
> 
> I believe an isb is owed here (DDI0487G.b D1.13.4). Annoyingly, I am
> having a hard time finding the same language in the H.a revision of the
> manual :-/

D1.3.6 probably is what you are looking for.

"Context synchronization event" is the key phrase to remember
when grepping through the ARM ARM. And yes, the new layout is
a nightmare (as if we really needed an additional 2800 pages...).

> 
>> +			     "msr daifset, #2\n"
>> +			     : : : "memory");
>> +	}
>> +}

[...]

>> +	/* tval should keep down-counting from 0 to -1. */
>> +	SET_COUNTER(DEF_CNT, test_args.timer);
>> +	timer_set_tval(test_args.timer, 0);
>> +	if (use_sched)
>> +		USERSPACE_SCHEDULE();
>> +	/* We just need 1 cycle to pass. */
>> +	isb();
> 
> Somewhat paranoid, but:
> 
> If the CPU retires the ISB much more quickly than the counter ticks, 
> its
> possible that you could observe an invalid TVAL even with a valid
> implementation.

Worse than that:

- ISB doesn't need to take any time at all. It just needs to ensure
   that everything is synchronised. Depending on how the CPU is built,
   this can come for free.

- There is no relation between the counter ticks and CPU cycles.

> What if you spin waiting for CNT to increment before the assertion? 
> Then
> you for sureknow (and can tell by reading the test) that the
> implementation is broken.

That's basically the only way to implement this. You can't rely
on any other event.

Thanks,

         M.
-- 
Jazz is not dead. It just smells funny...
_______________________________________________
kvmarm mailing list
kvmarm@lists.cs.columbia.edu
https://lists.cs.columbia.edu/mailman/listinfo/kvmarm

WARNING: multiple messages have this Message-ID (diff)
From: Marc Zyngier <maz@kernel.org>
To: Oliver Upton <oupton@google.com>
Cc: Ricardo Koller <ricarkol@google.com>,
	kvm@vger.kernel.org, kvmarm@lists.cs.columbia.edu,
	drjones@redhat.com, pbonzini@redhat.com,
	alexandru.elisei@arm.com, eric.auger@redhat.com,
	reijiw@google.com, rananta@google.com
Subject: Re: [PATCH v2 2/3] KVM: arm64: selftests: add arch_timer_edge_cases
Date: Thu, 17 Mar 2022 08:52:38 +0000	[thread overview]
Message-ID: <5fe2be916e1dcfe491fd3b40466d1932@kernel.org> (raw)
In-Reply-To: <YjLY5y+KObV0AR9g@google.com>

On 2022-03-17 06:44, Oliver Upton wrote:
> On Wed, Mar 16, 2022 at 09:51:26PM -0700, Ricardo Koller wrote:
>> Add an arch_timer edge-cases selftest. For now, just add some basic
>> sanity checks, and some stress conditions (like waiting for the timers
>> while re-scheduling the vcpu). The next commit will add the actual 
>> edge
>> case tests.
>> 
>> This test fails without a867e9d0cc1 "KVM: arm64: Don't miss pending
>> interrupts for suspended vCPU".
>> 
>> Reviewed-by: Reiji Watanabe <reijiw@google.com>
>> Reviewed-by: Raghavendra Rao Ananta <rananta@google.com>
>> Signed-off-by: Ricardo Koller <ricarkol@google.com>

[...]

>> +		asm volatile("wfi\n"
>> +			     "msr daifclr, #2\n"
>> +			     /* handle IRQ */
> 
> I believe an isb is owed here (DDI0487G.b D1.13.4). Annoyingly, I am
> having a hard time finding the same language in the H.a revision of the
> manual :-/

D1.3.6 probably is what you are looking for.

"Context synchronization event" is the key phrase to remember
when grepping through the ARM ARM. And yes, the new layout is
a nightmare (as if we really needed an additional 2800 pages...).

> 
>> +			     "msr daifset, #2\n"
>> +			     : : : "memory");
>> +	}
>> +}

[...]

>> +	/* tval should keep down-counting from 0 to -1. */
>> +	SET_COUNTER(DEF_CNT, test_args.timer);
>> +	timer_set_tval(test_args.timer, 0);
>> +	if (use_sched)
>> +		USERSPACE_SCHEDULE();
>> +	/* We just need 1 cycle to pass. */
>> +	isb();
> 
> Somewhat paranoid, but:
> 
> If the CPU retires the ISB much more quickly than the counter ticks, 
> its
> possible that you could observe an invalid TVAL even with a valid
> implementation.

Worse than that:

- ISB doesn't need to take any time at all. It just needs to ensure
   that everything is synchronised. Depending on how the CPU is built,
   this can come for free.

- There is no relation between the counter ticks and CPU cycles.

> What if you spin waiting for CNT to increment before the assertion? 
> Then
> you for sureknow (and can tell by reading the test) that the
> implementation is broken.

That's basically the only way to implement this. You can't rely
on any other event.

Thanks,

         M.
-- 
Jazz is not dead. It just smells funny...

  reply	other threads:[~2022-03-17  8:52 UTC|newest]

Thread overview: 20+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2022-03-17  4:51 [PATCH v2 0/3] KVM: arm64: selftests: Add edge cases tests for the arch timer Ricardo Koller
2022-03-17  4:51 ` Ricardo Koller
2022-03-17  4:51 ` [PATCH v2 1/3] KVM: arm64: selftests: add timer_get_tval() lib function Ricardo Koller
2022-03-17  4:51   ` Ricardo Koller
2022-03-17  4:51 ` [PATCH v2 2/3] KVM: arm64: selftests: add arch_timer_edge_cases Ricardo Koller
2022-03-17  4:51   ` Ricardo Koller
2022-03-17  6:44   ` Oliver Upton
2022-03-17  6:44     ` Oliver Upton
2022-03-17  8:52     ` Marc Zyngier [this message]
2022-03-17  8:52       ` Marc Zyngier
2022-03-17 16:56       ` Oliver Upton
2022-03-17 16:56         ` Oliver Upton
2022-03-18 20:49       ` Ricardo Koller
2022-03-18 20:49         ` Ricardo Koller
2022-03-17  4:51 ` [PATCH v2 3/3] KVM: arm64: selftests: add edge cases tests into arch_timer_edge_cases Ricardo Koller
2022-03-17  4:51   ` Ricardo Koller
2022-03-17  7:27   ` Oliver Upton
2022-03-17  7:27     ` Oliver Upton
2022-03-18 20:54     ` Ricardo Koller
2022-03-18 20:54       ` Ricardo Koller

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=5fe2be916e1dcfe491fd3b40466d1932@kernel.org \
    --to=maz@kernel.org \
    --cc=kvm@vger.kernel.org \
    --cc=kvmarm@lists.cs.columbia.edu \
    --cc=oupton@google.com \
    --cc=pbonzini@redhat.com \
    /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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.