From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id B4902C433F5 for ; Tue, 2 Nov 2021 11:09:41 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 9C37560F36 for ; Tue, 2 Nov 2021 11:09:41 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230519AbhKBLMP (ORCPT ); Tue, 2 Nov 2021 07:12:15 -0400 Received: from mail.kernel.org ([198.145.29.99]:33298 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229720AbhKBLMO (ORCPT ); Tue, 2 Nov 2021 07:12:14 -0400 Received: from disco-boy.misterjones.org (disco-boy.misterjones.org [51.254.78.96]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPSA id A183B60C41; Tue, 2 Nov 2021 11:09:39 +0000 (UTC) Received: from sofa.misterjones.org ([185.219.108.64] helo=why.misterjones.org) by disco-boy.misterjones.org with esmtpsa (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.94.2) (envelope-from ) id 1mhrfd-0032WN-EO; Tue, 02 Nov 2021 11:09:37 +0000 Date: Tue, 02 Nov 2021 11:09:37 +0000 Message-ID: <875ytaak5q.wl-maz@kernel.org> From: Marc Zyngier To: Oliver Upton Cc: kvmarm@lists.cs.columbia.edu, kvm@vger.kernel.org, James Morse , Alexandru Elisei , Suzuki K Poulose , linux-arm-kernel@lists.infradead.org, Andrew Jones , Peter Shier , Ricardo Koller , Reiji Watanabe Subject: Re: [PATCH v2 6/6] selftests: KVM: Test OS lock behavior In-Reply-To: <20211102094651.2071532-7-oupton@google.com> References: <20211102094651.2071532-1-oupton@google.com> <20211102094651.2071532-7-oupton@google.com> User-Agent: Wanderlust/2.15.9 (Almost Unreal) SEMI-EPG/1.14.7 (Harue) FLIM-LB/1.14.9 (=?UTF-8?B?R29qxY0=?=) APEL-LB/10.8 EasyPG/1.0.0 Emacs/27.1 (x86_64-pc-linux-gnu) MULE/6.0 (HANACHIRUSATO) MIME-Version: 1.0 (generated by SEMI-EPG 1.14.7 - "Harue") Content-Type: text/plain; charset=US-ASCII X-SA-Exim-Connect-IP: 185.219.108.64 X-SA-Exim-Rcpt-To: oupton@google.com, kvmarm@lists.cs.columbia.edu, kvm@vger.kernel.org, james.morse@arm.com, alexandru.elisei@arm.com, suzuki.poulose@arm.com, linux-arm-kernel@lists.infradead.org, drjones@redhat.com, pshier@google.com, ricarkol@google.com, reijiw@google.com X-SA-Exim-Mail-From: maz@kernel.org X-SA-Exim-Scanned: No (on disco-boy.misterjones.org); SAEximRunCond expanded to false Precedence: bulk List-ID: X-Mailing-List: kvm@vger.kernel.org Hi Oliver, On Tue, 02 Nov 2021 09:46:51 +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 > --- > .../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); > + 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); I haven't had a change to properly review the series, but this one definitely caught my eye. My expectations are that BRK is *not* affected by the OS Lock. The ARMv8 ARM goes as far as saying: Breakpoint Instruction exceptions are enabled regardless of the state of the OS Lock and the OS Double Lock. as well as: There is no enable control for Breakpoint Instruction exceptions. They are always enabled, and cannot be masked. I wonder how your test succeeds, though. Thanks, M. -- Without deviation from the norm, progress is not possible.