From patchwork Thu Aug 25 05:08:46 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Reiji Watanabe X-Patchwork-Id: 12954209 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 498E7C28D13 for ; Thu, 25 Aug 2022 05:13:47 +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=o3TV825xgN39k8Dip70blZ88bk3wQxL0Hh7QOOmfo3M=; b=JcoN2z9qjizkv3KXP+/gmTw/ZJ ufp8xk4Nuxff2oREhCJZXmOcH8vaRoyet9LSxfrTNcNrNxYB7+1WxAo/Y1V2ckNrmcxHczCFkVKd+ YlhaeM64Kh0XVR6xEGS9o+QL6FRrwYkatPW5obJP+N35bDueXdJ8VP2McNTW7Vgynv+t2zp2a1/jM +w3fFpNox15FXy2vy/Ob6i7UL7evhJFjVjJPtzm7scLNBgfjYzOlaAw2PR5T3FY5vG7l5/9jlBIHY rYCe4oHF3gZDiQLIyTotAwsBTvVUKbbAPQfYZS4EoacV1wj59OCnQrhX3phIusHU+FYRlQiZGruRw pAwEOUJw==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.94.2 #2 (Red Hat Linux)) id 1oR5AS-007FX9-Vs; Thu, 25 Aug 2022 05:12:37 +0000 Received: from mail-yw1-x114a.google.com ([2607:f8b0:4864:20::114a]) by bombadil.infradead.org with esmtps (Exim 4.94.2 #2 (Red Hat Linux)) id 1oR58O-007Ddv-RW for linux-arm-kernel@lists.infradead.org; Thu, 25 Aug 2022 05:10:30 +0000 Received: by mail-yw1-x114a.google.com with SMTP id 00721157ae682-337ed9110c2so283711077b3.15 for ; Wed, 24 Aug 2022 22:10:27 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20210112; h=cc:to:from:subject:references:mime-version:message-id:in-reply-to :date:from:to:cc; bh=YHlnoTuvqCkIHNzVEvPhjo0XVRSspND21mglVFldtsg=; b=S4z6ByMKPaz7v0TqyBPudcw0RcL/LIRHleuf4PcPxUkw0lVnru6Bdvk/I6csdzNys9 i95i3qO5w/JbpaEjD35NQZQta1f1kb4LdfeboJm99NQQys23YMVdjQjAJmOcZKVCXTJs zvVC9Nlwn5Y/iaySbFCJEiMHZSeygT7AjdovUTHx9btnsLyd4Ig2BeizYl5cOuknmKHK eZporwgkevI0ZITNmGKaY6gRjvJaDNEE92bHFa3GqxrBpzvLEFngo2Ak9mMDrF9pA+2S eoL6QPAlLOaDQfNGjRQAziKcsck0iRfSag7UeKPxS0LlE1/zPR+oQ5aUSzvHbv91ezBr oW0w== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=cc:to:from:subject:references:mime-version:message-id:in-reply-to :date:x-gm-message-state:from:to:cc; bh=YHlnoTuvqCkIHNzVEvPhjo0XVRSspND21mglVFldtsg=; b=mqyhS5kR3MSPo+ZbWbQ/hcNVxaQbB/p6C8z9HPUR9AUzAX2NIXG1lA6IWnvMgPJmqb vT7ceLuYEN8ULipTK5F+JZVkPcHvgxjxaFoW/ED9pUaMD8RtMDNVeQ4iKd4QVLzX+uYy WkVF8hipNIlccOPUWFMhk7RHXYzPjTuyoseQydlasRkrRlAqQTCNLqAA2EMWxatE7e/g 2QuFTVAtkfkZ6kmo6gS3mdeBNrV80SUBJSsLiIUL6nNfBV0WpjSwFPU6grD0UK4GjbYl Yjb1XXUWAn+yLc3rQr4O1Vwp0cW7m5E9cbMhqQG1hkXrN20nYKI8keHlHuqK7R/nyVv8 My6A== X-Gm-Message-State: ACgBeo2PAjqWYzeM53Pbu+F87tN+ARfmSC3A4kyn6WnomDYjaw+1AttV tu/jvNMXpSNUdOATGYXLRx5AxVY1S7g= X-Google-Smtp-Source: AA6agR60smgqTg7FqVsKr00Rx1ARhb9FLWG6n/rkbAzF0Rp9rt1QNn0dvCk9m1oXln0XP7RzE1TOPpoc+8w= X-Received: from reijiw-west4.c.googlers.com ([fda3:e722:ac3:cc00:20:ed76:c0a8:aa1]) (user=reijiw job=sendgmr) by 2002:a25:58d:0:b0:695:ea5e:5311 with SMTP id 135-20020a25058d000000b00695ea5e5311mr2069649ybf.370.1661404227271; Wed, 24 Aug 2022 22:10:27 -0700 (PDT) Date: Wed, 24 Aug 2022 22:08:46 -0700 In-Reply-To: <20220825050846.3418868-1-reijiw@google.com> Message-Id: <20220825050846.3418868-10-reijiw@google.com> Mime-Version: 1.0 References: <20220825050846.3418868-1-reijiw@google.com> X-Mailer: git-send-email 2.37.1.595.g718a3a8f04-goog Subject: [PATCH 9/9] 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 , Andrew Jones , 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-20220824_221028_932731_24B3713B X-CRM114-Status: GOOD ( 15.02 ) 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 Currently, the debug-exceptions test always uses only {break,watch}point#0 and the highest numbered context-aware breakpoint. Modify the test to use all {break,watch}points and context-aware breakpoints supported on the system. Signed-off-by: Reiji Watanabe --- .../selftests/kvm/aarch64/debug-exceptions.c | 77 +++++++++++++++---- 1 file changed, 61 insertions(+), 16 deletions(-) diff --git a/tools/testing/selftests/kvm/aarch64/debug-exceptions.c b/tools/testing/selftests/kvm/aarch64/debug-exceptions.c index dc94c85bb383..7aeab6ae887a 100644 --- a/tools/testing/selftests/kvm/aarch64/debug-exceptions.c +++ b/tools/testing/selftests/kvm/aarch64/debug-exceptions.c @@ -397,14 +397,12 @@ static int debug_version(uint64_t id_aa64dfr0) return cpuid_get_ufield(id_aa64dfr0, ID_AA64DFR0_DEBUGVER_SHIFT); } -int main(int argc, char *argv[]) +void run_test(uint8_t bpn, uint8_t wpn, uint8_t ctx_bpn) { struct kvm_vcpu *vcpu; struct kvm_vm *vm; struct ucall uc; int stage; - uint64_t aa64dfr0; - uint8_t brps; vm = vm_create_with_one_vcpu(&vcpu, guest_code); ucall_init(vm, NULL); @@ -412,10 +410,6 @@ int main(int argc, char *argv[]) vm_init_descriptor_tables(vm); vcpu_init_descriptor_tables(vcpu); - vcpu_get_reg(vcpu, KVM_ARM64_SYS_REG(SYS_ID_AA64DFR0_EL1), &aa64dfr0); - __TEST_REQUIRE(debug_version(aa64dfr0) >= 6, - "Armv8 debug architecture not supported."); - vm_install_sync_handler(vm, VECTOR_SYNC_CURRENT, ESR_EC_BRK_INS, guest_sw_bp_handler); vm_install_sync_handler(vm, VECTOR_SYNC_CURRENT, @@ -427,15 +421,9 @@ int main(int argc, char *argv[]) vm_install_sync_handler(vm, VECTOR_SYNC_CURRENT, ESR_EC_SVC64, guest_svc_handler); - /* Number of breakpoints, minus 1 */ - brps = cpuid_get_ufield(aa64dfr0, ID_AA64DFR0_BRPS_SHIFT); - __TEST_REQUIRE(brps > 0, "At least two breakpoints are required"); - - /* - * Run tests with breakpoint#0 and watchpoint#0, and the higiest - * numbered (context-aware) breakpoint. - */ - vcpu_args_set(vcpu, 3, 0, 0, brps); + /* Specify bpn/wpn/ctx_bpn to be tested */ + vcpu_args_set(vcpu, 3, bpn, wpn, ctx_bpn); + pr_debug("Use bpn#%d, wpn#%d and ctx_bpn#%d\n", bpn, wpn, ctx_bpn); for (stage = 0; stage < 11; stage++) { vcpu_run(vcpu); @@ -458,5 +446,62 @@ 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_get_ufield(aa64dfr0, ID_AA64DFR0_BRPS_SHIFT); + __TEST_REQUIRE(brps > 0, "At least two breakpoints are required"); + + wrps = cpuid_get_ufield(aa64dfr0, ID_AA64DFR0_WRPS_SHIFT); + ctx_cmps = cpuid_get_ufield(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; + + /* Run tests with all supported breakpoints/watchpoints */ + 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; + struct kvm_vcpu *vcpu; + uint64_t aa64dfr0; + + vm = vm_create_with_one_vcpu(&vcpu, guest_code); + vcpu_get_reg(vcpu, KVM_ARM64_SYS_REG(SYS_ID_AA64DFR0_EL1), &aa64dfr0); + kvm_vm_free(vm); + + __TEST_REQUIRE(debug_version(aa64dfr0) >= 6, + "Armv8 debug architecture not supported."); + + /* Run debug tests with the default configuration */ + test_debug(aa64dfr0); return 0; }