From: Ricardo Koller <ricarkol@google.com>
To: Oliver Upton <oupton@google.com>
Cc: kvmarm@lists.cs.columbia.edu, kvm@vger.kernel.org,
Marc Zyngier <maz@kernel.org>, James Morse <james.morse@arm.com>,
Alexandru Elisei <alexandru.elisei@arm.com>,
Suzuki K Poulose <suzuki.poulose@arm.com>,
linux-arm-kernel@lists.infradead.org,
Andrew Jones <drjones@redhat.com>,
Peter Shier <pshier@google.com>,
Reiji Watanabe <reijiw@google.com>
Subject: Re: [PATCH v2 6/6] selftests: KVM: Test OS lock behavior
Date: Tue, 2 Nov 2021 16:27:22 -0700 [thread overview]
Message-ID: <YYHJWmQ+RmNZ51dM@google.com> (raw)
In-Reply-To: <20211102094651.2071532-7-oupton@google.com>
On Tue, Nov 02, 2021 at 09:46:51AM +0000, Oliver Upton wrote:
> KVM now correctly handles the OS Lock for its guests. When set, KVM
> blocks all debug exceptions originating from the guest. Add test cases
> to the debug-exceptions test to assert that software breakpoint,
> hardware breakpoint, watchpoint, and single-step exceptions are in fact
> blocked.
>
> Signed-off-by: Oliver Upton <oupton@google.com>
> ---
> .../selftests/kvm/aarch64/debug-exceptions.c | 58 ++++++++++++++++++-
> 1 file changed, 56 insertions(+), 2 deletions(-)
>
> diff --git a/tools/testing/selftests/kvm/aarch64/debug-exceptions.c b/tools/testing/selftests/kvm/aarch64/debug-exceptions.c
> index e5e6c92b60da..6b6ff81cdd23 100644
> --- a/tools/testing/selftests/kvm/aarch64/debug-exceptions.c
> +++ b/tools/testing/selftests/kvm/aarch64/debug-exceptions.c
> @@ -23,7 +23,7 @@
> #define SPSR_D (1 << 9)
> #define SPSR_SS (1 << 21)
>
> -extern unsigned char sw_bp, hw_bp, bp_svc, bp_brk, hw_wp, ss_start;
> +extern unsigned char sw_bp, hw_bp, hw_bp2, bp_svc, bp_brk, hw_wp, ss_start;
> static volatile uint64_t sw_bp_addr, hw_bp_addr;
> static volatile uint64_t wp_addr, wp_data_addr;
> static volatile uint64_t svc_addr;
> @@ -47,6 +47,14 @@ static void reset_debug_state(void)
> isb();
> }
>
> +static void enable_os_lock(void)
> +{
> + write_sysreg(oslar_el1, 1);
should be: write_sysreg(val, reg);
> + isb();
> +
> + GUEST_ASSERT(read_sysreg(oslsr_el1) & 2);
> +}
> +
> static void install_wp(uint64_t addr)
> {
> uint32_t wcr;
> @@ -99,6 +107,7 @@ static void guest_code(void)
> GUEST_SYNC(0);
>
> /* Software-breakpoint */
> + reset_debug_state();
> asm volatile("sw_bp: brk #0");
> GUEST_ASSERT_EQ(sw_bp_addr, PC(sw_bp));
>
> @@ -152,6 +161,51 @@ static void guest_code(void)
> GUEST_ASSERT_EQ(ss_addr[1], PC(ss_start) + 4);
> GUEST_ASSERT_EQ(ss_addr[2], PC(ss_start) + 8);
>
> + GUEST_SYNC(6);
> +
> + /* OS Lock blocking software-breakpoint */
> + reset_debug_state();
> + enable_os_lock();
> + sw_bp_addr = 0;
> + asm volatile("brk #0");
> + GUEST_ASSERT_EQ(sw_bp_addr, 0);
> +
> + GUEST_SYNC(7);
> +
> + /* OS Lock blocking hardware-breakpoint */
> + reset_debug_state();
> + enable_os_lock();
> + install_hw_bp(PC(hw_bp2));
> + hw_bp_addr = 0;
> + asm volatile("hw_bp2: nop");
> + GUEST_ASSERT_EQ(hw_bp_addr, 0);
> +
> + GUEST_SYNC(8);
> +
> + /* OS Lock blocking watchpoint */
> + reset_debug_state();
> + enable_os_lock();
> + write_data = '\0';
> + wp_data_addr = 0;
> + install_wp(PC(write_data));
> + write_data = 'x';
> + GUEST_ASSERT_EQ(write_data, 'x');
> + GUEST_ASSERT_EQ(wp_data_addr, 0);
> +
> + GUEST_SYNC(9);
> +
> + /* OS Lock blocking single-step */
> + reset_debug_state();
> + enable_os_lock();
> + ss_addr[0] = 0;
> + install_ss();
> + ss_idx = 0;
> + asm volatile("mrs x0, esr_el1\n\t"
> + "add x0, x0, #1\n\t"
> + "msr daifset, #8\n\t"
> + : : : "x0");
> + GUEST_ASSERT_EQ(ss_addr[0], 0);
> +
> GUEST_DONE();
> }
>
> @@ -223,7 +277,7 @@ int main(int argc, char *argv[])
> vm_install_sync_handler(vm, VECTOR_SYNC_CURRENT,
> ESR_EC_SVC64, guest_svc_handler);
>
> - for (stage = 0; stage < 7; stage++) {
> + for (stage = 0; stage < 11; stage++) {
> vcpu_run(vm, VCPU_ID);
>
> switch (get_ucall(vm, VCPU_ID, &uc)) {
> --
> 2.33.1.1089.g2158813163f-goog
>
_______________________________________________
linux-arm-kernel mailing list
linux-arm-kernel@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/linux-arm-kernel
next prev parent reply other threads:[~2021-11-02 23:28 UTC|newest]
Thread overview: 22+ messages / expand[flat|nested] mbox.gz Atom feed top
2021-11-02 9:46 [PATCH v2 0/6] KVM: arm64: Emulate the OS lock Oliver Upton
2021-11-02 9:46 ` [PATCH v2 1/6] KVM: arm64: Correctly treat writes to OSLSR_EL1 as undefined Oliver Upton
2021-11-04 2:40 ` Reiji Watanabe
2021-11-02 9:46 ` [PATCH v2 2/6] KVM: arm64: Stash OSLSR_EL1 in the cpu context Oliver Upton
2021-11-02 9:51 ` Oliver Upton
2021-11-04 3:37 ` Reiji Watanabe
2021-11-02 9:46 ` [PATCH v2 3/6] KVM: arm64: Allow guest to set the OSLK bit Oliver Upton
2021-11-04 3:31 ` Reiji Watanabe
2021-11-04 3:47 ` Ricardo Koller
2021-11-04 4:40 ` Oliver Upton
2021-11-02 9:46 ` [PATCH v2 4/6] KVM: arm64: Emulate the OS Lock Oliver Upton
2021-11-02 23:45 ` Ricardo Koller
2021-11-03 0:35 ` Oliver Upton
2021-11-05 3:56 ` Reiji Watanabe
2021-11-05 5:36 ` Oliver Upton
2021-11-02 9:46 ` [PATCH v2 5/6] selftests: KVM: Add OSLSR_EL1 to the list of blessed regs Oliver Upton
2021-11-02 9:46 ` [PATCH v2 6/6] selftests: KVM: Test OS lock behavior Oliver Upton
2021-11-02 11:09 ` Marc Zyngier
2021-11-02 14:53 ` Oliver Upton
2021-11-02 20:01 ` Oliver Upton
2021-11-02 23:27 ` Ricardo Koller [this message]
2021-11-02 23:36 ` Oliver Upton
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=YYHJWmQ+RmNZ51dM@google.com \
--to=ricarkol@google.com \
--cc=alexandru.elisei@arm.com \
--cc=drjones@redhat.com \
--cc=james.morse@arm.com \
--cc=kvm@vger.kernel.org \
--cc=kvmarm@lists.cs.columbia.edu \
--cc=linux-arm-kernel@lists.infradead.org \
--cc=maz@kernel.org \
--cc=oupton@google.com \
--cc=pshier@google.com \
--cc=reijiw@google.com \
--cc=suzuki.poulose@arm.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 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).