From patchwork Tue Apr 19 06:55:43 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Reiji Watanabe X-Patchwork-Id: 12817551 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 7CF7AC433EF for ; Tue, 19 Apr 2022 07:24:46 +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=gmQvumar64hzc6TNod6jm3qKbJ0hPCe0j5qOOt8im+o=; b=u7npbaoOxwdaJliXwSBIBKSXUb FypwZtdH/nOfOO2kApeAi4xGbcdRjdJLK5KOaPIgVSVgh1FYPpMvdx4areb9z3fejF9/+GqRjy7EP c01XKeDvF91r20DQvdIPX9J4w/EbKNvmd7YQtD3gnZHOVMAVFAwn/DcKpngZHnCmoVsHLkRmEEHHE BWdTV7pJG3hmOnbT3nM6LwWrp5vXsnJdQOwV/vn/l0tt0fW34FoQymyYtIZSo7VjUekc5Bw6J17ke vcRh7tf3NGZpTnYMIaV4t7jI9FWZPHvA/pJAoHlzxHcJHksTI1S3TTa4y6IM9O6c20QM1cJhXlD3O 1VPlKbBQ==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.94.2 #2 (Red Hat Linux)) id 1ngiCr-001xNh-F2; Tue, 19 Apr 2022 07:23:27 +0000 Received: from mail-pj1-x1049.google.com ([2607:f8b0:4864:20::1049]) by bombadil.infradead.org with esmtps (Exim 4.94.2 #2 (Red Hat Linux)) id 1nghoM-001nq0-Gt for linux-arm-kernel@lists.infradead.org; Tue, 19 Apr 2022 06:58:10 +0000 Received: by mail-pj1-x1049.google.com with SMTP id s13-20020a17090a764d00b001cb896b75ffso10133600pjl.6 for ; Mon, 18 Apr 2022 23:58:05 -0700 (PDT) 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=Q/YanX6EPfx+u+3OMqrYAFeJvrZlkb0TikNUTqVME1Y=; b=A9RjQxSTslkChFxxKJBdhdGh7KoE8jdKMtCpxERX/tBbu9UdykN6mkSjBGbvrYe0yp xBFHJ43ZJf4RR+MEhIlZ7ADb8RRTxk9EjoI4axpGew5mfnR/CZ+7Qc08BTxvdSIhMnEL S0VoLAtGwG0N9/MEUw8RgUNNusNRqxJ2rnhriVmUw0Daui4T115Gk7aB5kAT/K7Dy5ln Sqz+L0yKZ5Fwv8xGNj0xOmz6XDBQvxHX8WWsVY9iNm2YwZF/W72gKnWRD+fPNYWpGwuL Z7r0lVt6DSqTfiRLp6FxJ/jy9xJU8u1FN9hBZqz308wPv0h3JB04kzgRohXhz+W+dL4+ fwVQ== 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=Q/YanX6EPfx+u+3OMqrYAFeJvrZlkb0TikNUTqVME1Y=; b=TorgjCDWeD8yJklERDCsGeKPI2Qb382OIMv9S5tMt2XIWffvq/4Z9Jz9b8A3PBxhHs 5/RCKDoGQjeDW8DoggzTxWTIUJqneLKGySiJZLIHKmdwOyYU2jbXcmvlEXZoti0JGQtX 5F7mGd0obyQm28lucLmyt9WJsRlqhSaYi0EMx21YQoZdy/g0lSTUsP2Z6CAMDkw59Zjs biZCgLS8OLaaywlHxZC+7VhIAvU+PGrXH6x+vVqXJm1ma2yOdX+kof97zMKo+SDHOBrm LSBHV0AbCKIhrxkK04qKb6LoGa8PQ1PGrNnquQRvIq7eMo8GhpVD6w46uHXaGVjOPJLX zr1g== X-Gm-Message-State: AOAM532UEQ0mDrzw2J8goIarSfxj06SRT6Svm+TORoqC5vwhRxXjyVHK I0d8cD7orlLc0qLD6c9Cx/kpkfpC5hI= X-Google-Smtp-Source: ABdhPJwE2z7KVThLseGHNOhepGcvcWOJLfCs0hdmn9Is1cTsX8Yz9n5jIjhtaxYpBfwuDusFcqDN9vQu4DQ= X-Received: from reiji-vws-sp.c.googlers.com ([fda3:e722:ac3:cc00:7f:e700:c0a8:3d59]) (user=reijiw job=sendgmr) by 2002:a62:685:0:b0:50a:5870:10b1 with SMTP id 127-20020a620685000000b0050a587010b1mr13751101pfg.61.1650351485348; Mon, 18 Apr 2022 23:58:05 -0700 (PDT) Date: Mon, 18 Apr 2022 23:55:43 -0700 In-Reply-To: <20220419065544.3616948-1-reijiw@google.com> Message-Id: <20220419065544.3616948-38-reijiw@google.com> Mime-Version: 1.0 References: <20220419065544.3616948-1-reijiw@google.com> X-Mailer: git-send-email 2.36.0.rc0.470.gd361397f0d-goog Subject: [PATCH v7 37/38] KVM: arm64: selftests: Test with every breakpoint/watchpoint From: Reiji Watanabe To: Marc Zyngier , kvmarm@lists.cs.columbia.edu Cc: kvm@vger.kernel.org, linux-arm-kernel@lists.infradead.org, James Morse , Alexandru Elisei , Suzuki K Poulose , Paolo Bonzini , Will Deacon , Andrew Jones , Fuad Tabba , Peng Liang , Peter Shier , Ricardo Koller , Oliver Upton , Jing Zhang , Raghavendra Rao Anata , Reiji Watanabe X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20220418_235806_646326_42F1D4DC X-CRM114-Status: GOOD ( 14.91 ) 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 Add test cases that uses every breakpoint/watchpoint to the debug-exceptions test. Signed-off-by: Reiji Watanabe --- .../selftests/kvm/aarch64/debug-exceptions.c | 70 ++++++++++++++++--- 1 file changed, 59 insertions(+), 11 deletions(-) diff --git a/tools/testing/selftests/kvm/aarch64/debug-exceptions.c b/tools/testing/selftests/kvm/aarch64/debug-exceptions.c index 4e00100b9aa1..829fad6c7d58 100644 --- a/tools/testing/selftests/kvm/aarch64/debug-exceptions.c +++ b/tools/testing/selftests/kvm/aarch64/debug-exceptions.c @@ -701,7 +701,7 @@ static void check_debug_regs(struct kvm_vm *vm, uint32_t vcpu, } } -int main(int argc, char *argv[]) +void run_test(uint8_t bpn, uint8_t wpn, uint8_t ctx_bpn) { struct kvm_vm *vm; struct ucall uc; @@ -710,6 +710,8 @@ int main(int argc, char *argv[]) uint8_t nbps, nwps; bool debug_reg_test = false; + pr_debug("%s bpn:%d, wpn:%d, ctx_bpn:%d\n", __func__, bpn, wpn, ctx_bpn); + vm = vm_create_default(VCPU_ID, 0, guest_code); ucall_init(vm, NULL); @@ -717,11 +719,6 @@ int main(int argc, char *argv[]) vcpu_init_descriptor_tables(vm, VCPU_ID); get_reg(vm, VCPU_ID, KVM_ARM64_SYS_REG(SYS_ID_AA64DFR0_EL1), &aa64dfr0); - if (cpuid_extract_uftr(aa64dfr0, ID_AA64DFR0_DEBUGVER_SHIFT) < 6) { - print_skip("Armv8 debug architecture not supported."); - kvm_vm_free(vm); - exit(KSFT_SKIP); - } vm_install_sync_handler(vm, VECTOR_SYNC_CURRENT, ESR_EC_BRK_INS, guest_sw_bp_handler); @@ -742,11 +739,7 @@ int main(int argc, char *argv[]) nwps = cpuid_extract_uftr(aa64dfr0, ID_AA64DFR0_WRPS_SHIFT) + 1; TEST_ASSERT(nwps >= 2, "Number of watchpoints must be >= 2"); - /* - * Test with breakpoint#0 and watchpoint#0, and the higiest - * numbered breakpoint (the context aware breakpoint). - */ - vcpu_args_set(vm, VCPU_ID, 4, &debug_regs, 0, 0, nbps - 1); + vcpu_args_set(vm, VCPU_ID, 4, &debug_regs, bpn, wpn, ctx_bpn); for (stage = 0; stage < 13; stage++) { /* First two stages are sanity debug regs read/write check */ @@ -783,5 +776,60 @@ int main(int argc, char *argv[]) done: kvm_vm_free(vm); +} + +/* + * Run debug testing using the various breakpoint#, watchpoint# and + * context-aware breakpoint# with the given ID_AA64DFR0_EL1 configuration. + */ +void test_debug(uint64_t aa64dfr0) +{ + uint8_t brps, wrps, ctx_cmps; + uint8_t normal_brp_num, wrp_num, ctx_brp_base, ctx_brp_num; + int b, w, c; + + brps = cpuid_extract_uftr(aa64dfr0, ID_AA64DFR0_BRPS_SHIFT); + wrps = cpuid_extract_uftr(aa64dfr0, ID_AA64DFR0_WRPS_SHIFT); + ctx_cmps = cpuid_extract_uftr(aa64dfr0, ID_AA64DFR0_CTX_CMPS_SHIFT); + + pr_debug("%s brps:%d, wrps:%d, ctx_cmps:%d\n", __func__, + brps, wrps, ctx_cmps); + + /* Number of normal (non-context aware) breakpoints */ + normal_brp_num = brps - ctx_cmps; + + /* Number of watchpoints */ + wrp_num = wrps + 1; + + /* Number of context aware breakpoints */ + ctx_brp_num = ctx_cmps + 1; + + /* Lowest context aware breakpoint number */ + ctx_brp_base = normal_brp_num; + + for (c = ctx_brp_base; c < ctx_brp_base + ctx_brp_num; c++) { + for (b = 0; b < normal_brp_num; b++) { + for (w = 0; w < wrp_num; w++) + run_test(b, w, c); + } + } +} + +int main(int argc, char *argv[]) +{ + struct kvm_vm *vm; + uint64_t aa64dfr0; + + vm = vm_create_default(VCPU_ID, 0, guest_code); + get_reg(vm, VCPU_ID, KVM_ARM64_SYS_REG(SYS_ID_AA64DFR0_EL1), &aa64dfr0); + kvm_vm_free(vm); + + if (cpuid_extract_uftr(aa64dfr0, ID_AA64DFR0_DEBUGVER_SHIFT) < 6) { + print_skip("Armv8 debug architecture not supported."); + exit(KSFT_SKIP); + } + + /* Run debug tests with the default configuration */ + test_debug(aa64dfr0); return 0; }