From patchwork Tue Nov 23 21:01:09 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Oliver Upton X-Patchwork-Id: 12693507 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 bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id 1B198C433EF for ; Tue, 23 Nov 2021 21:04:32 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20210309; h=Sender: Content-Transfer-Encoding:Content-Type:List-Subscribe:List-Help:List-Post: List-Archive:List-Unsubscribe:List-Id:Cc:To:From:Subject:References: Mime-Version:Message-Id:In-Reply-To:Date:Reply-To:Content-ID: Content-Description:Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc :Resent-Message-ID:List-Owner; bh=h7HT4btuWnYytMC12PqKpUlNhSa8zlh1FNt4CitcPOI=; b=bRX0JObm+pSSDzU9Rf6gk6vkKJ 7v5RlRkh4T7g+s9q5BRDt5Be5fVMTGzl+CU7JmVUCuzaTpoZolLDiXHFYPhefDiy8E+eTthiujhHB RvbzB5Qt6wjeL/985Q89dMwZGS6unQN4zilpdCsNLjhD4Y6gfbbvkHX/o5Vk49WdtWvV9qqtFlsPG 8zpY0NOATgJSqgmyIaNZ2fVKp+gg+p2VtnTR828UC3cJKmK73boJCHqo/RyZzh1xpe2h8kOKy1jFL +DEPkYoVp3ixScq3kWHMyZKXGZBm658Ym1PFq4DZ87hZB2OBKKHsCrsFgBjI21A0097vsemBMuge6 iMgTiiuA==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.94.2 #2 (Red Hat Linux)) id 1mpcwK-003TAo-6S; Tue, 23 Nov 2021 21:02:56 +0000 Received: from mail-il1-x14a.google.com ([2607:f8b0:4864:20::14a]) by bombadil.infradead.org with esmtps (Exim 4.94.2 #2 (Red Hat Linux)) id 1mpcup-003SlB-VX for linux-arm-kernel@lists.infradead.org; Tue, 23 Nov 2021 21:01:25 +0000 Received: by mail-il1-x14a.google.com with SMTP id l5-20020a056e021aa500b00297fbfb0647so189981ilv.22 for ; Tue, 23 Nov 2021 13:01:22 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20210112; h=date:in-reply-to:message-id:mime-version:references:subject:from:to :cc; bh=QovEQZReWLCATlIewYReLSWnyKrpm0FAX1JqfLYj0ZU=; b=GvxugeqPapYQXmol2OKna0PSxEK0dRKHL03g/3jvj+NM5Zo7aVD2DG0NvLay0HO677 u37OJrSwS3hYQkPMeG9OPNDK3f5YlepZsarr5VR5FXJ3GzdgcA1WLud2TXRThVIwB3O3 uFBaAR9z5ybAU8wVwhudaNSob5oTY6HD3FYTLzAkAA2v/HWOLuQIbQ00MfSI5rHIwb4U EQj3zNf2Yu9oKJfDoHW9KOcpcgKFoky0D6I8y/cOXeR9TlfzGc8dOAO6BTNHDfvAobT6 S3wQ5KluJYABG0zyuDuLXmdYh2Zph6J0bzlLmR0vuXQ70MJkP1SXgy8ttvxpcqa7sHwQ 8IkA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:date:in-reply-to:message-id:mime-version :references:subject:from:to:cc; bh=QovEQZReWLCATlIewYReLSWnyKrpm0FAX1JqfLYj0ZU=; b=i0O2Cg0Yr4/3SYlG0hf5iBigGORCFv0Tw/bLobWrDsyuyouw2XRUCTEuoCrRADKMlv Ob8cyACH4Tic0gWR6QUcqWNAK7hAf3Jl0NBZf0w1YpaQU2Wfnk2Ot6qYol9WZy/PsF+3 ZY8rjzX9ke0494ggWpF/2Cq4F4+7YsmjUed2uGykbk3yCSWwYFVtI73rJpLRvz7AkJ6u xzZ5NqS46PZvCsb6GXpmAQUrelfAKpw4iqZUWffPD+jBE53v9Xp8Lhf/2IPuPNYos56E 577j0ifMGm7/YHo4/T0C0b62P1quSNzGGXfCcXj5sNybTP3TGjBDG+n9bUriZ+pCMfxI Du5A== X-Gm-Message-State: AOAM532fCFwDx9URohw1pIDMkFJrHL+3WxxQ/Do4K7rQeO+km57Pn4PM C+U4zyimvKGzRmQ6cnnQXHhUwg2I0nM= X-Google-Smtp-Source: ABdhPJwTgu9XjIzS0u9PqlLGX0GOMfjHnkXYfd2F5tiYZIseel2tjBlN9HerYxahKvrn7lMiFo9d0WYzcmE= X-Received: from oupton.c.googlers.com ([fda3:e722:ac3:cc00:2b:ff92:c0a8:404]) (user=oupton job=sendgmr) by 2002:a02:ba8b:: with SMTP id g11mr9410034jao.128.1637701282229; Tue, 23 Nov 2021 13:01:22 -0800 (PST) Date: Tue, 23 Nov 2021 21:01:09 +0000 In-Reply-To: <20211123210109.1605642-1-oupton@google.com> Message-Id: <20211123210109.1605642-7-oupton@google.com> Mime-Version: 1.0 References: <20211123210109.1605642-1-oupton@google.com> X-Mailer: git-send-email 2.34.0.rc2.393.gf8c9666880-goog Subject: [PATCH v3 6/6] selftests: KVM: Test OS lock behavior From: Oliver Upton To: kvmarm@lists.cs.columbia.edu Cc: kvm@vger.kernel.org, Marc Zyngier , James Morse , Alexandru Elisei , Suzuki K Poulose , linux-arm-kernel@lists.infradead.org, Andrew Jones , Peter Shier , Ricardo Koller , Reiji Watanabe , Oliver Upton X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20211123_130124_043788_4112E294 X-CRM114-Status: GOOD ( 12.00 ) X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.34 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+linux-arm-kernel=archiver.kernel.org@lists.infradead.org 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 ea189d83abf7..63b2178210c4 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, sw_bp2, 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(1, oslar_el1); + 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 does not block software-breakpoint */ + reset_debug_state(); + enable_os_lock(); + sw_bp_addr = 0; + asm volatile("sw_bp2: brk #0"); + GUEST_ASSERT_EQ(sw_bp_addr, PC(sw_bp2)); + + 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)) {