From patchwork Thu Aug 25 05:08:38 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Reiji Watanabe X-Patchwork-Id: 12954191 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 7CF42C28D13 for ; Thu, 25 Aug 2022 05:11:11 +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=MtPocaeH9i3iwLPvJN/KXjABz4zg1nTzDO3JLilEyAw=; b=40VpDPuHMQPRDVb2npln7XVqMA ata+bbDdCyjbK2bb+pCpTDnRX/VbtRx1zmp2Vi8tVEs5nw88eCGK6oKY+CKrsV6XKwinrSsfxbKPU 0gH4OIwBly9rz/IpoYUWKcDlojo5GBYq/EEo95+ruB1YKx+WVY4jtTBWoXemMUiPR4WAY33bS1AHl fNJNoK4Bnp+JGgHDnWzTROrD4xcsu5P6yDdzCbzrDpmfZa0yMbBvBntlGC/PY9mR7S7eTjJwbyhiU pvTZ73ZOiuI2zBspIs3E85qjQWLcgXh8qTs8rvhCvi8mIs5GuN8Ty+ZBzyvJTlIDktUaZ3Uw3oZz7 TWAs3DZQ==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.94.2 #2 (Red Hat Linux)) id 1oR581-007DQx-Jz; Thu, 25 Aug 2022 05:10:05 +0000 Received: from mail-yw1-x1149.google.com ([2607:f8b0:4864:20::1149]) by bombadil.infradead.org with esmtps (Exim 4.94.2 #2 (Red Hat Linux)) id 1oR57z-007DOR-6z for linux-arm-kernel@lists.infradead.org; Thu, 25 Aug 2022 05:10:04 +0000 Received: by mail-yw1-x1149.google.com with SMTP id 00721157ae682-334370e5ab9so328451867b3.22 for ; Wed, 24 Aug 2022 22:09:59 -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=Q3hjf8MS4AzzCWp5/oCSzOsoQ1ZbyBHYLyXOhMM4IQU=; b=VcczpBcdz/1D305XYzhC6q4QuudDMoUbJqkU5dHnorb9t4TPC3YwLgmqsMEgbahnh2 +hfdMdra6lWeBABxnmLdId4Ay0ymjcNv5EE4jwqvZ2EibwlPZAZAz6kqcHdQR+jrui9V 3Y90iiBnvUuscRTb5mNg1fDqOSXTCsWuDQ83fJ5FSRid5MLS6CNxBUG7Iy/V95SQ3Tng 5nGiaioEr1PWX94QrqMYngmxniCLA0gWbZ7FG+9v0DlrN7P/DkVhTT8u3leAUgc7zos2 MW4e0TWfavCUFfS++lbscSG4VwEa4ERsBnaAV3U678vU7DDvmy6klM5GBI/dJBos8c/p OXqw== 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=Q3hjf8MS4AzzCWp5/oCSzOsoQ1ZbyBHYLyXOhMM4IQU=; b=P58caEXMoefneAff+lfE2UFSN4A8KiJoqZa6MBxOoA9ZKAX8wpQ7GjMYXum7PkQL/7 XvziwR24cijbbILmKsxlGDfZi5X5EBt7K8gnNG3gvd+ZHbYHG+No0TI1pZaNRtgUURDx KsVJlmT83WCBjNoJinuqe1i9lv1EQt7WdGRUXJxKQKFO2o3nMGjB+DlE01AaNSsCfHev kVnkxfBA9XKNS9k6CTO1CaXvhoJrRQf+xk29aRyUj0oUcoCybQKAY9inDm5HXVnJ1Q1r I77/n55VEbb8ff9tPN2AZ2GPONtn1zr8QnAPtvvquVeLW25IrGeA1ULrEQr5YSLRM45Q ipvw== X-Gm-Message-State: ACgBeo0nWrKOzVbbjEGApEFpfR1Pw8L6PqT262+o6/spm6CfL5hPYHFT jalJy5EgWCsovAyiy1VG6mibaMRN7Nw= X-Google-Smtp-Source: AA6agR58GZbl6co9b3RXWIjzW0YOxe8HSUhxD7OeeygT/Iu7A8ou68w797ekVXhGcdByFqk3CBisadep1EQ= X-Received: from reijiw-west4.c.googlers.com ([fda3:e722:ac3:cc00:20:ed76:c0a8:aa1]) (user=reijiw job=sendgmr) by 2002:a25:6d88:0:b0:695:9728:f253 with SMTP id i130-20020a256d88000000b006959728f253mr2035825ybc.39.1661404199334; Wed, 24 Aug 2022 22:09:59 -0700 (PDT) Date: Wed, 24 Aug 2022 22:08:38 -0700 In-Reply-To: <20220825050846.3418868-1-reijiw@google.com> Message-Id: <20220825050846.3418868-2-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 1/9] KVM: arm64: selftests: Add helpers to extract a field of an ID register 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_221003_294824_16C00FE4 X-CRM114-Status: UNSURE ( 8.88 ) X-CRM114-Notice: Please train this message. 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 Introduce helpers to extract a field of an ID register. Subsequent patches will use those helpers. Signed-off-by: Reiji Watanabe --- .../selftests/kvm/include/aarch64/processor.h | 2 ++ .../testing/selftests/kvm/lib/aarch64/processor.c | 15 +++++++++++++++ 2 files changed, 17 insertions(+) diff --git a/tools/testing/selftests/kvm/include/aarch64/processor.h b/tools/testing/selftests/kvm/include/aarch64/processor.h index a8124f9dd68a..a9b4b4e0e592 100644 --- a/tools/testing/selftests/kvm/include/aarch64/processor.h +++ b/tools/testing/selftests/kvm/include/aarch64/processor.h @@ -193,4 +193,6 @@ void smccc_hvc(uint32_t function_id, uint64_t arg0, uint64_t arg1, uint32_t guest_get_vcpuid(void); +int cpuid_get_sfield(uint64_t val, int field_shift); +unsigned int cpuid_get_ufield(uint64_t val, int field_shift); #endif /* SELFTEST_KVM_PROCESSOR_H */ diff --git a/tools/testing/selftests/kvm/lib/aarch64/processor.c b/tools/testing/selftests/kvm/lib/aarch64/processor.c index 6f5551368944..0b2ad46e7ff5 100644 --- a/tools/testing/selftests/kvm/lib/aarch64/processor.c +++ b/tools/testing/selftests/kvm/lib/aarch64/processor.c @@ -528,3 +528,18 @@ void smccc_hvc(uint32_t function_id, uint64_t arg0, uint64_t arg1, [arg4] "r"(arg4), [arg5] "r"(arg5), [arg6] "r"(arg6) : "x0", "x1", "x2", "x3", "x4", "x5", "x6", "x7"); } + +/* Helpers to get a signed/unsigned feature field from ID register value */ +int cpuid_get_sfield(uint64_t val, int field_shift) +{ + int width = 4; + + return (int64_t)(val << (64 - width - field_shift)) >> (64 - width); +} + +unsigned int cpuid_get_ufield(uint64_t val, int field_shift) +{ + int width = 4; + + return (uint64_t)(val << (64 - width - field_shift)) >> (64 - width); +} From patchwork Thu Aug 25 05:08:39 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Reiji Watanabe X-Patchwork-Id: 12954192 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 47B59C04AA5 for ; Thu, 25 Aug 2022 05:11:18 +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=el9Gmx6198JSfkzClZSgEpB6vbUcx+hT14D6SAajB28=; b=UPK66fEHMWOi+bPxaqkQrVmN2+ OpTd/fU7rqf2DB86vXetBYidppQf7yxDK6TrmUpuWkPxPTBh13XGRBZvYkGso1w4Be7u5tWRt3EEZ J+Ew13tXetmlTXJpwSAJmDcABgzmkZpYta2dpdkY1atwHGhO4tWZ1+I/Dfp3aI97yooWfbI2QPvUK /cVZ7zMd6KgTFBPUcA/pyeX3/i05XV1gcabaTEBKPDsQf6KvfjBZ6eYlx4tO49BOvcuyISD66DWFl /2dU/WfB8fwgJlljKogSjJdN65X8RBshaMKl/IFUcNtQWHfMcC9iGUnerrLawcaX9764BHofFeKK3 9jE/CfFw==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.94.2 #2 (Red Hat Linux)) id 1oR58B-007DXg-Kb; Thu, 25 Aug 2022 05:10:15 +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 1oR589-007DVd-9F for linux-arm-kernel@lists.infradead.org; Thu, 25 Aug 2022 05:10:14 +0000 Received: by mail-yw1-x114a.google.com with SMTP id 00721157ae682-31f5960500bso325520397b3.14 for ; Wed, 24 Aug 2022 22:10:12 -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=mbWwPoUmijWxZF1qqEuvmzXuoM73rXdJ5r3D+vU7B94=; b=r8VhFLOaJT2TiUfv5+8axKHdrA7rd9E3CpESCV4oQAWgvQswx5RdABZz3ahHrg7fzv ttpqQCCUQxkXo+K4PSCAiJwLlIaaNI9WnmqxpF8e1QHDG8fgfywLytaA1eDi6Kafx/8u +cqUU1Yg8lR/QkMl2G0o6DiG4wglSuwNEh07eEhQMwELJ4u8LQ4Ym/Szse8yiZp2eWL9 18+wMWphGzs99MzWHLecuNFbW868I3BVRiBJ23r8/6RJxC2HLGBRSeD7dMi6+d08vtuW tLAg3yvOYQsfnzGwFL1sfHzqISWlVUCuJhgEfXtUq1zr2KOI9BDEInIwHt+eIFjCjBPO loTQ== 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=mbWwPoUmijWxZF1qqEuvmzXuoM73rXdJ5r3D+vU7B94=; b=fXfsFmQV6PQe4ofk5UXZP8JNg4IPkJ1LmKkxrMJ+uRt2008TysR+A2iwypas44mGYF k8ojOFoKvVGBWek+ocvZZEkMeF7lTcj24V1e3Mcc4sLHZ729Tm1BiI9cPOp9G0tMAot6 r1LwX0qL9HpFhP3/c8gKGHLX0pV9beFsg8qSyeTAykfxWiPfgUmaDz+SpaH08vXXSgys WVsN+RArWZ1A8R3um03t9PWedTsO0rSh9u/RDlA68n4De1Hcvi/3NhxYS9LW4xVy1dvd 8P87T4qTuPYxM3nWSpM95d0oB0GGYr5CG77KH94JSrbh0f2HwkS+5VRB8ilLo9gKIOFf gY3w== X-Gm-Message-State: ACgBeo0q8DvTS/kKfvTVbsXpq+E+G+t70LdtE/mqrNKRdVbdxc2+r9Ox Fd6aISbC4ykKSzhfReUPGl1XVbiUlmY= X-Google-Smtp-Source: AA6agR6Y3Gi8FMQjP63JX1oEF6pk6Y3m+wYPfkv8vdoUapXy4ra3FJcrC1HheWBCS6yZioM75J0QQ0KL4KQ= X-Received: from reijiw-west4.c.googlers.com ([fda3:e722:ac3:cc00:20:ed76:c0a8:aa1]) (user=reijiw job=sendgmr) by 2002:a25:2f4a:0:b0:695:8b9a:1788 with SMTP id v71-20020a252f4a000000b006958b9a1788mr1971181ybv.126.1661404211856; Wed, 24 Aug 2022 22:10:11 -0700 (PDT) Date: Wed, 24 Aug 2022 22:08:39 -0700 In-Reply-To: <20220825050846.3418868-1-reijiw@google.com> Message-Id: <20220825050846.3418868-3-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 2/9] KVM: arm64: selftests: Add write_dbg{b,w}{c,v}r helpers in debug-exceptions 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_221013_348758_9F38AB80 X-CRM114-Status: GOOD ( 10.53 ) 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 Introduce helpers in the debug-exceptions test to write to dbg{b,w}{c,v}r registers. Those helpers will be useful for test cases that will be added to the test in subsequent patches. Signed-off-by: Reiji Watanabe Reviewed-by: Ricardo Koller --- .../selftests/kvm/aarch64/debug-exceptions.c | 72 +++++++++++++++++-- 1 file changed, 68 insertions(+), 4 deletions(-) diff --git a/tools/testing/selftests/kvm/aarch64/debug-exceptions.c b/tools/testing/selftests/kvm/aarch64/debug-exceptions.c index 2ee35cf9801e..51047e6b8db3 100644 --- a/tools/testing/selftests/kvm/aarch64/debug-exceptions.c +++ b/tools/testing/selftests/kvm/aarch64/debug-exceptions.c @@ -28,6 +28,69 @@ static volatile uint64_t svc_addr; static volatile uint64_t ss_addr[4], ss_idx; #define PC(v) ((uint64_t)&(v)) +#define GEN_DEBUG_WRITE_REG(reg_name) \ +static void write_##reg_name(int num, uint64_t val) \ +{ \ + switch (num) { \ + case 0: \ + write_sysreg(val, reg_name##0_el1); \ + break; \ + case 1: \ + write_sysreg(val, reg_name##1_el1); \ + break; \ + case 2: \ + write_sysreg(val, reg_name##2_el1); \ + break; \ + case 3: \ + write_sysreg(val, reg_name##3_el1); \ + break; \ + case 4: \ + write_sysreg(val, reg_name##4_el1); \ + break; \ + case 5: \ + write_sysreg(val, reg_name##5_el1); \ + break; \ + case 6: \ + write_sysreg(val, reg_name##6_el1); \ + break; \ + case 7: \ + write_sysreg(val, reg_name##7_el1); \ + break; \ + case 8: \ + write_sysreg(val, reg_name##8_el1); \ + break; \ + case 9: \ + write_sysreg(val, reg_name##9_el1); \ + break; \ + case 10: \ + write_sysreg(val, reg_name##10_el1); \ + break; \ + case 11: \ + write_sysreg(val, reg_name##11_el1); \ + break; \ + case 12: \ + write_sysreg(val, reg_name##12_el1); \ + break; \ + case 13: \ + write_sysreg(val, reg_name##13_el1); \ + break; \ + case 14: \ + write_sysreg(val, reg_name##14_el1); \ + break; \ + case 15: \ + write_sysreg(val, reg_name##15_el1); \ + break; \ + default: \ + GUEST_ASSERT(0); \ + } \ +} + +/* Define write_dbgbcr()/write_dbgbvr()/write_dbgwcr()/write_dbgwvr() */ +GEN_DEBUG_WRITE_REG(dbgbcr) +GEN_DEBUG_WRITE_REG(dbgbvr) +GEN_DEBUG_WRITE_REG(dbgwcr) +GEN_DEBUG_WRITE_REG(dbgwvr) + static void reset_debug_state(void) { asm volatile("msr daifset, #8"); @@ -59,8 +122,9 @@ static void install_wp(uint64_t addr) uint32_t mdscr; wcr = DBGWCR_LEN8 | DBGWCR_RD | DBGWCR_WR | DBGWCR_EL1 | DBGWCR_E; - write_sysreg(wcr, dbgwcr0_el1); - write_sysreg(addr, dbgwvr0_el1); + write_dbgwcr(0, wcr); + write_dbgwvr(0, addr); + isb(); asm volatile("msr daifclr, #8"); @@ -76,8 +140,8 @@ static void install_hw_bp(uint64_t addr) uint32_t mdscr; bcr = DBGBCR_LEN8 | DBGBCR_EXEC | DBGBCR_EL1 | DBGBCR_E; - write_sysreg(bcr, dbgbcr0_el1); - write_sysreg(addr, dbgbvr0_el1); + write_dbgbcr(0, bcr); + write_dbgbvr(0, addr); isb(); asm volatile("msr daifclr, #8"); From patchwork Thu Aug 25 05:08:40 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Reiji Watanabe X-Patchwork-Id: 12954193 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 13866C04AA5 for ; Thu, 25 Aug 2022 05:11:33 +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=f8AGq2wLMwqPRYIdY8q2qieu352PYjUwXc5QfO55XNM=; b=jB5DogXOx+iMZ+r7Jrwc8FjQZ1 uBEOpAFR/Rwm7tsRfBj6Xbre17yHrnJhEP3w/eMkqPYf/4mkT+OX7HqX8BAf3vCE3aqCfYWhhpmo5 huuIwOsB08782uo50rplsk/ZHepTWVEX9LUeR5IsepLCOV07JUiFDjypRR+TGDVu6oz7koKnWMUwK AGGJd3Y1mgmm6Q9qztcPitLxtoWDHDW7fHKzBxEAnPgziNrQUVy8xsR/INXzq/tzVQUr/yVKEiuUj 4gNjmANIJVvj0criewNfO6aOWm+euThDhdigUYIpA7qnLlVR8ENgZgSyVf38bBuiLylfevy46I4Rp UN/wuk1w==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.94.2 #2 (Red Hat Linux)) id 1oR58O-007Ddy-Bm; Thu, 25 Aug 2022 05:10:28 +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 1oR58B-007DWU-7P for linux-arm-kernel@lists.infradead.org; Thu, 25 Aug 2022 05:10:16 +0000 Received: by mail-yw1-x114a.google.com with SMTP id 00721157ae682-335420c7bfeso326530157b3.16 for ; Wed, 24 Aug 2022 22:10:14 -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=9ffUjEySqAKD1W3MR1Jll+z7zRBzaKpJ63e87b2sI0w=; b=Y2XgBKslzFhyyaeuMJTAUVbJclGK2+/4xYvY6Ym/8KydSI8gTBWYAeRwKuZYtS+QXO M0BoxBQrLDT4cHZzCw2tWZDbE5ck4054YjeYeUjJsYmc+VVPIGaF3kKsGw+DjgZUK+uy vXAickHOiwUViKy5QQBUm5r2NxTAzgC2dx4uq6+JB13u17Z6BuO0bdA5XxrIMS684azZ fVDTX6qgO9KdVOL8iYI0vPnVur2yMCm9OxrPQd1AyF8wwFI6xzkEpP0ZrT2DehZH1WVv yYQ/b8Dxs/GYb7s97082W3qCi52LSalo97F7Tuqs2nSZd1WJ4mgDvkmdfFecwDmDyMzq nkmQ== 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=9ffUjEySqAKD1W3MR1Jll+z7zRBzaKpJ63e87b2sI0w=; b=wnLA6TtBBSsv0RJb2VhxbLZCaqu5PTKbfGxUUqsQrfBb0rMKqi2/44rZHojpUMDAc+ lfV5ylBS34f95WN8xL17FYQCIonTyvUm05tjkjFlhtjlcttt0bO/cCR1vplI6mxPVHxX +ZG+6TashLpR7sqP01yacde7M9PC08gY6wSLkBGqhSj8seRjR1rr3osU6bePwqFzh7HT 2unWJft5FMzBe2jq/asaKnAp8uu4Y9xqa7SXHr+ZKpCDTdWCCuR/ru1QwWp0sxlXzscY 3KgC8aGUXTg4JVGWfQqOSHsOpS3e4Iirexr/P0Hx9jXiOJtb23Dy4zY/ypZAABCrci3W 0yKg== X-Gm-Message-State: ACgBeo2NvENG4bcBovxDr7Eslh7mhn4m+v8FcLFknpSrmgG7QtPInqlF 62JbOo8dxixElA0VwKzQiD9uOvTEaKk= X-Google-Smtp-Source: AA6agR71nOpX8pLKJKTNxFaWjIc4FLSWuNTbDZPoIKZQIn8/WYBy8Y7fVJOMwWjOvv8y7dwtbE/1RQ9qK04= X-Received: from reijiw-west4.c.googlers.com ([fda3:e722:ac3:cc00:20:ed76:c0a8:aa1]) (user=reijiw job=sendgmr) by 2002:a5b:a0f:0:b0:691:6fea:deda with SMTP id k15-20020a5b0a0f000000b006916feadedamr2092344ybq.377.1661404214009; Wed, 24 Aug 2022 22:10:14 -0700 (PDT) Date: Wed, 24 Aug 2022 22:08:40 -0700 In-Reply-To: <20220825050846.3418868-1-reijiw@google.com> Message-Id: <20220825050846.3418868-4-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 3/9] KVM: arm64: selftests: Remove the hard-coded {b,w}pn#0 from debug-exceptions 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_221015_305756_E37E55CF X-CRM114-Status: GOOD ( 13.01 ) 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 Remove the hard-coded {break,watch}point #0 from the guest_code() in debug-exceptions to allow {break,watch}point number to be specified. Subsequent patches will add test cases for non-zero {break,watch}points. Signed-off-by: Reiji Watanabe Reviewed-by: Ricardo Koller --- .../selftests/kvm/aarch64/debug-exceptions.c | 50 ++++++++++++------- 1 file changed, 32 insertions(+), 18 deletions(-) diff --git a/tools/testing/selftests/kvm/aarch64/debug-exceptions.c b/tools/testing/selftests/kvm/aarch64/debug-exceptions.c index 51047e6b8db3..183ee16acb7d 100644 --- a/tools/testing/selftests/kvm/aarch64/debug-exceptions.c +++ b/tools/testing/selftests/kvm/aarch64/debug-exceptions.c @@ -93,6 +93,9 @@ GEN_DEBUG_WRITE_REG(dbgwvr) static void reset_debug_state(void) { + uint8_t brps, wrps, i; + uint64_t dfr0; + asm volatile("msr daifset, #8"); write_sysreg(0, osdlr_el1); @@ -100,11 +103,20 @@ static void reset_debug_state(void) isb(); write_sysreg(0, mdscr_el1); - /* This test only uses the first bp and wp slot. */ - write_sysreg(0, dbgbvr0_el1); - write_sysreg(0, dbgbcr0_el1); - write_sysreg(0, dbgwcr0_el1); - write_sysreg(0, dbgwvr0_el1); + + /* Reset all bcr/bvr/wcr/wvr registers */ + dfr0 = read_sysreg(id_aa64dfr0_el1); + brps = cpuid_get_ufield(dfr0, ID_AA64DFR0_BRPS_SHIFT); + for (i = 0; i <= brps; i++) { + write_dbgbcr(i, 0); + write_dbgbvr(i, 0); + } + wrps = cpuid_get_ufield(dfr0, ID_AA64DFR0_WRPS_SHIFT); + for (i = 0; i <= wrps; i++) { + write_dbgwcr(i, 0); + write_dbgwvr(i, 0); + } + isb(); } @@ -116,14 +128,14 @@ static void enable_os_lock(void) GUEST_ASSERT(read_sysreg(oslsr_el1) & 2); } -static void install_wp(uint64_t addr) +static void install_wp(uint8_t wpn, uint64_t addr) { uint32_t wcr; uint32_t mdscr; wcr = DBGWCR_LEN8 | DBGWCR_RD | DBGWCR_WR | DBGWCR_EL1 | DBGWCR_E; - write_dbgwcr(0, wcr); - write_dbgwvr(0, addr); + write_dbgwcr(wpn, wcr); + write_dbgwvr(wpn, addr); isb(); @@ -134,14 +146,14 @@ static void install_wp(uint64_t addr) isb(); } -static void install_hw_bp(uint64_t addr) +static void install_hw_bp(uint8_t bpn, uint64_t addr) { uint32_t bcr; uint32_t mdscr; bcr = DBGBCR_LEN8 | DBGBCR_EXEC | DBGBCR_EL1 | DBGBCR_E; - write_dbgbcr(0, bcr); - write_dbgbvr(0, addr); + write_dbgbcr(bpn, bcr); + write_dbgbvr(bpn, addr); isb(); asm volatile("msr daifclr, #8"); @@ -164,7 +176,7 @@ static void install_ss(void) static volatile char write_data; -static void guest_code(void) +static void guest_code(uint8_t bpn, uint8_t wpn) { GUEST_SYNC(0); @@ -177,7 +189,7 @@ static void guest_code(void) /* Hardware-breakpoint */ reset_debug_state(); - install_hw_bp(PC(hw_bp)); + install_hw_bp(bpn, PC(hw_bp)); asm volatile("hw_bp: nop"); GUEST_ASSERT_EQ(hw_bp_addr, PC(hw_bp)); @@ -185,7 +197,7 @@ static void guest_code(void) /* Hardware-breakpoint + svc */ reset_debug_state(); - install_hw_bp(PC(bp_svc)); + install_hw_bp(bpn, PC(bp_svc)); asm volatile("bp_svc: svc #0"); GUEST_ASSERT_EQ(hw_bp_addr, PC(bp_svc)); GUEST_ASSERT_EQ(svc_addr, PC(bp_svc) + 4); @@ -194,7 +206,7 @@ static void guest_code(void) /* Hardware-breakpoint + software-breakpoint */ reset_debug_state(); - install_hw_bp(PC(bp_brk)); + install_hw_bp(bpn, PC(bp_brk)); asm volatile("bp_brk: brk #0"); GUEST_ASSERT_EQ(sw_bp_addr, PC(bp_brk)); GUEST_ASSERT_EQ(hw_bp_addr, PC(bp_brk)); @@ -203,7 +215,7 @@ static void guest_code(void) /* Watchpoint */ reset_debug_state(); - install_wp(PC(write_data)); + install_wp(wpn, PC(write_data)); write_data = 'x'; GUEST_ASSERT_EQ(write_data, 'x'); GUEST_ASSERT_EQ(wp_data_addr, PC(write_data)); @@ -237,7 +249,7 @@ static void guest_code(void) /* OS Lock blocking hardware-breakpoint */ reset_debug_state(); enable_os_lock(); - install_hw_bp(PC(hw_bp2)); + install_hw_bp(bpn, PC(hw_bp2)); hw_bp_addr = 0; asm volatile("hw_bp2: nop"); GUEST_ASSERT_EQ(hw_bp_addr, 0); @@ -249,7 +261,7 @@ static void guest_code(void) enable_os_lock(); write_data = '\0'; wp_data_addr = 0; - install_wp(PC(write_data)); + install_wp(wpn, PC(write_data)); write_data = 'x'; GUEST_ASSERT_EQ(write_data, 'x'); GUEST_ASSERT_EQ(wp_data_addr, 0); @@ -337,6 +349,8 @@ int main(int argc, char *argv[]) vm_install_sync_handler(vm, VECTOR_SYNC_CURRENT, ESR_EC_SVC64, guest_svc_handler); + /* Run tests with breakpoint#0 and watchpoint#0. */ + vcpu_args_set(vcpu, 2, 0, 0); for (stage = 0; stage < 11; stage++) { vcpu_run(vcpu); From patchwork Thu Aug 25 05:08:41 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Reiji Watanabe X-Patchwork-Id: 12954194 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 DC245C04AA5 for ; Thu, 25 Aug 2022 05:11:48 +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=MH++ES/yZTd1iKIC/VcsAyxIg81mJN4ccLkMn21k4yg=; b=ky1YGwN0kDFzNTKPoFUVduPz/h ykW2APRdS+DXfgyx21u8Do6Yu+myviIDzYlnXt46VGJ8in3puvNu85v3VervS6w5or3PNBN1kL7n1 IxnD1MatrjccuR+gwU2UQIEzk+TQ6hHSgJ1mWvicB0Vfb2kJxlBacqr4GMPIMXBASQuBvXIM8nK1k pwSJtgDeZ83RTc7STF57zMWEoZAihhY+aiUmIwi7TvSHCbPNjIY5gRA4ska00JIDNYR/88INeaLkM Rz6LwhVMXeiFc7TbhlVNmkzdnAyi4cGIq3jqzVk42s/bYNEAU2jGMK5Vr5aoH/afXk5Rb/svOtUlC n7oBhoXw==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.94.2 #2 (Red Hat Linux)) id 1oR58c-007Dt5-M4; Thu, 25 Aug 2022 05:10:43 +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 1oR58D-007DYG-Fk for linux-arm-kernel@lists.infradead.org; Thu, 25 Aug 2022 05:10:18 +0000 Received: by mail-yw1-x114a.google.com with SMTP id 00721157ae682-33352499223so325298357b3.8 for ; Wed, 24 Aug 2022 22:10:16 -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=8oX+5M8AEKJji1mM4AdRdiIeL9hn/q6yl0Bz7273pVA=; b=LeLhe13n76eUMhCg8SWeTVrWKNtcglEFQyn+mfy6n1dzAkWuQysdlKISXEtK+nMY8e KFHp3ByAxQkIys2eIl+f4hu/uA+oD6EZJNE/nEotAQeMIFarEHGOqga1SN984jZVdz/5 N4Aza75aQ6ogp2RnHch+Zsn6Jalu1DrSU4kripuc0ELF5fnewHCu0Gn3vChBs1tgDaYd ADLEDy9zjAvrnk0uMK/T8HwpKQEAjAsqwE75J8fM/9mscrSuleHrzT67O3Y+FrHMSlaM uIsU6jEl8gn0OGNrQY/Fyk8idl1C4Cd9nBvGbyaOjjPwxpFmo+kDKFVMJMHLPRiAikRk k7mQ== 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=8oX+5M8AEKJji1mM4AdRdiIeL9hn/q6yl0Bz7273pVA=; b=S58V43X6s2O8KpE8BzJAACGCj4rNO33pTGNWXfj9L2aGrlzkPoHAh32FxNASPjT7Hz r9REXOVXI5tuUjDtThWxHSo9oYgea9kgesjYKHhWxCjpMABo5OY4AttUIza0vZJadv/A amYvOvTBlh8RwvvwTprhjVBOWx15etRZ3XYj2Ozxl/0dL8rzb9It4SZ4RYc76PZfGO4q e2brIsanJzAicWo40ILukRAoEOD7BVwZ78TtwISnMs821HHF2/bPrOBOz9B0V2KUXF2o ovYMJnxHJ1cvqBwASgly7Ddytk+0mkuD1Yxwmu73tIMY5Ry4dGJQLn3iMUuMF7as/jvm SGYQ== X-Gm-Message-State: ACgBeo2EUUYrW9OwTrkXvYOK7UdwCmYHtshK3v+f8QT05MZ5AlyAtOp3 ShTGECieoPZluU3Cyeb6UFriNcnhmSU= X-Google-Smtp-Source: AA6agR52jNE2uqaO7jEYMgZLpa+TwESVpjsc/w6zjrZheJdPE8MUiS+G/MUXsFxHt1MmvGcr0ODLhNAfaxQ= X-Received: from reijiw-west4.c.googlers.com ([fda3:e722:ac3:cc00:20:ed76:c0a8:aa1]) (user=reijiw job=sendgmr) by 2002:a5b:2cb:0:b0:688:ecfc:5865 with SMTP id h11-20020a5b02cb000000b00688ecfc5865mr2015078ybp.642.1661404216176; Wed, 24 Aug 2022 22:10:16 -0700 (PDT) Date: Wed, 24 Aug 2022 22:08:41 -0700 In-Reply-To: <20220825050846.3418868-1-reijiw@google.com> Message-Id: <20220825050846.3418868-5-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 4/9] KVM: arm64: selftests: Add helpers to enable debug exceptions 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_221017_556810_F72FCD14 X-CRM114-Status: UNSURE ( 9.06 ) X-CRM114-Notice: Please train this message. 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 helpers to enable breakpoint and watchpoint exceptions. Signed-off-by: Reiji Watanabe Reviewed-by: Oliver Upton Reviewed-by: Ricardo Koller --- .../selftests/kvm/aarch64/debug-exceptions.c | 25 ++++++++++--------- 1 file changed, 13 insertions(+), 12 deletions(-) diff --git a/tools/testing/selftests/kvm/aarch64/debug-exceptions.c b/tools/testing/selftests/kvm/aarch64/debug-exceptions.c index 183ee16acb7d..713c7240b680 100644 --- a/tools/testing/selftests/kvm/aarch64/debug-exceptions.c +++ b/tools/testing/selftests/kvm/aarch64/debug-exceptions.c @@ -128,10 +128,20 @@ static void enable_os_lock(void) GUEST_ASSERT(read_sysreg(oslsr_el1) & 2); } +static void enable_debug_bwp_exception(void) +{ + uint32_t mdscr; + + asm volatile("msr daifclr, #8"); + + mdscr = read_sysreg(mdscr_el1) | MDSCR_KDE | MDSCR_MDE; + write_sysreg(mdscr, mdscr_el1); + isb(); +} + static void install_wp(uint8_t wpn, uint64_t addr) { uint32_t wcr; - uint32_t mdscr; wcr = DBGWCR_LEN8 | DBGWCR_RD | DBGWCR_WR | DBGWCR_EL1 | DBGWCR_E; write_dbgwcr(wpn, wcr); @@ -139,28 +149,19 @@ static void install_wp(uint8_t wpn, uint64_t addr) isb(); - asm volatile("msr daifclr, #8"); - - mdscr = read_sysreg(mdscr_el1) | MDSCR_KDE | MDSCR_MDE; - write_sysreg(mdscr, mdscr_el1); - isb(); + enable_debug_bwp_exception(); } static void install_hw_bp(uint8_t bpn, uint64_t addr) { uint32_t bcr; - uint32_t mdscr; bcr = DBGBCR_LEN8 | DBGBCR_EXEC | DBGBCR_EL1 | DBGBCR_E; write_dbgbcr(bpn, bcr); write_dbgbvr(bpn, addr); isb(); - asm volatile("msr daifclr, #8"); - - mdscr = read_sysreg(mdscr_el1) | MDSCR_KDE | MDSCR_MDE; - write_sysreg(mdscr, mdscr_el1); - isb(); + enable_debug_bwp_exception(); } static void install_ss(void) From patchwork Thu Aug 25 05:08:42 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Reiji Watanabe X-Patchwork-Id: 12954206 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 58485C04AA5 for ; Thu, 25 Aug 2022 05:12:25 +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=AjVnJsGRmi46J0DwAM+Tja24HIfTjVYNFLI9TWYdKvQ=; b=uFy8P1ak9reyabQJGOl6Rewc68 DpN18Ul+nI/odC2EFCYtBhV5WfDD9nNkF+eFFnEBQQK7RtT6QsuEgrwKNdeaA7LEmldgSKeMu7j+Y mU++Xvuw7yV4mYjG8N628PXEfHX89TeCzsuoiuGCknvWNO9/BzzY60zWZN23ZtODdWZLrA75KNVzb X3JeQFH0DgZf0lykSsBneWYPLMXcgJ6ydG2X1YAe+nVoyOaHSqmJA0Zm1TBNCCK8EcVt9GChoEBQt PHZAznYOGAPC37gmTRDwL3x7iuE4WbWWksaU4TEFb5U+/TKh72kg54m72F/iNlfXNPtxz/QGNx6Qw bXFSmBwA==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.94.2 #2 (Red Hat Linux)) id 1oR59D-007EN0-4a; Thu, 25 Aug 2022 05:11:19 +0000 Received: from mail-pj1-x104a.google.com ([2607:f8b0:4864:20::104a]) by bombadil.infradead.org with esmtps (Exim 4.94.2 #2 (Red Hat Linux)) id 1oR58I-007DZO-NY for linux-arm-kernel@lists.infradead.org; Thu, 25 Aug 2022 05:10:24 +0000 Received: by mail-pj1-x104a.google.com with SMTP id oo12-20020a17090b1c8c00b001faa0b549caso2275738pjb.0 for ; Wed, 24 Aug 2022 22:10:19 -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=pEzlhIhHkJ9oe9us+Ap6efv2GvV7LuN1d5BuceK5HtQ=; b=GDyPQuvB4CGkscQbFZesosca0zjSklRpbtqexkueZNX0/pQlIx18BczSNbJOP6N52r VK0YZIjzcrbwa8JnR5p94cA3vM3FOALNsiaDpTwkEQ5sYP8zR2+ZCDGSbAHtV1d2ntKO 1nscFoy1pN1GJ/KqunnMWBDzX60HpvGeV1ZFpeTg2j/LI9cFvBStu4bK+XXveF0y/P93 iIpNZOY8Cm/V3G+MHqg8np+I0RwEFmMV9x4YMP+uyhlRuqHaRf87tYe6/Jaha/2Nqe24 hjZfCUriCXxAGqR5uLeTWRpq8z3vDgesV9E3/ACXNMNELEY5hwkQ7ZH9wBrfCwDKEHHR b/+w== 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=pEzlhIhHkJ9oe9us+Ap6efv2GvV7LuN1d5BuceK5HtQ=; b=wf4/NYbeHF4uBF/vESzvOXFMIlPPfIYTZkcoaTmR//isioyopLCm1iVfE+lipzMOdY V6lIyOaDIPvxvUDogzTtNGZVJFBlJFvM8cJFkUK8aLPvQbamSegz+MHcVqDvPzkr62uj eZ+pKWR9Q3YiQl0yQyIb+8qaA0EcEWLT0QZr22Mig7MOHydoEWZcZ4XdLFC7Yog3cIBK nSVIN+B4tySMZLrhzizvJ84nUC82dLMANusasMJU7mO5aTGnuj4FpTGv7rNWG1jtNgpe Kq0QuJktiZjJbjmz0kIZm4TvE4FnEznBy3k5/ww6mlrLBsf8SzbJZPpE7w54SFyulP+U GjQQ== X-Gm-Message-State: ACgBeo1Dj84viPcFeUBsKd1b8pbyfOGvWtkYvnY2D/k0xH3xmcYbwdaK Rg/yW2hkrl8ApjxtyvFhDUznMULyfH8= X-Google-Smtp-Source: AA6agR4QwGnPgJc9EXrJlzOPJDZW1awp7QnK0mmHC+92n4anJ3Yqks2hO/x4pF1tFVBJVUjLL44mvc2Kwdg= X-Received: from reijiw-west4.c.googlers.com ([fda3:e722:ac3:cc00:20:ed76:c0a8:aa1]) (user=reijiw job=sendgmr) by 2002:a17:90a:de96:b0:1fa:e427:e18e with SMTP id n22-20020a17090ade9600b001fae427e18emr12097875pjv.116.1661404218605; Wed, 24 Aug 2022 22:10:18 -0700 (PDT) Date: Wed, 24 Aug 2022 22:08:42 -0700 In-Reply-To: <20220825050846.3418868-1-reijiw@google.com> Message-Id: <20220825050846.3418868-6-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 5/9] KVM: arm64: selftests: Have debug_version() use cpuid_get_ufield() helper 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_221022_785459_81A2D8A8 X-CRM114-Status: GOOD ( 11.06 ) 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 Change debug_version() to use cpuid_get_ufield() to extract DebugVer field from the AA64DFR0_EL1 register value. Signed-off-by: Reiji Watanabe --- tools/testing/selftests/kvm/aarch64/debug-exceptions.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tools/testing/selftests/kvm/aarch64/debug-exceptions.c b/tools/testing/selftests/kvm/aarch64/debug-exceptions.c index 713c7240b680..17b17359ac41 100644 --- a/tools/testing/selftests/kvm/aarch64/debug-exceptions.c +++ b/tools/testing/selftests/kvm/aarch64/debug-exceptions.c @@ -320,7 +320,7 @@ static int debug_version(struct kvm_vcpu *vcpu) uint64_t id_aa64dfr0; vcpu_get_reg(vcpu, KVM_ARM64_SYS_REG(SYS_ID_AA64DFR0_EL1), &id_aa64dfr0); - return id_aa64dfr0 & 0xf; + return cpuid_get_ufield(id_aa64dfr0, ID_AA64DFR0_DEBUGVER_SHIFT); } int main(int argc, char *argv[]) From patchwork Thu Aug 25 05:08: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: 12954205 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 88FA8C04AA5 for ; Thu, 25 Aug 2022 05:12:09 +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=K1EPcmVoOZr6QU2OTt+0kZeLhPYdhShk7Kpu+a/4aro=; b=EGDqt/653fM3HLuW//ugSHZsAc c9GJeqJcFSppJQy6NATlHOo5aG6iin9lEBulnbtZlZRi+SUxWuZY8BMdlUPK3vZ3jxCmoazI7Srve CoF48R2i3RNK1gK3t9C8Y3Tp6UrHwM0O4WzQK53cP9B2yvJM9dc+pA09RFGrvcPgjZfNtf6HPgwwW X7Gu4ZKmW2QGgegMWiVwZuxhBIi7ZtC6DU8T0n+128BWykH1mhro+nO9ZIAMHAY6fzWWUr2r+A0lo 6OKXcBLvxi2a3qIQC9HZYN3qeXRi0XUo1ci6bjBj9QhBTZxlMER/UYmEApT0jkEKydwM9bRihldK+ Y+6/kz9A==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.94.2 #2 (Red Hat Linux)) id 1oR58x-007E7e-UP; Thu, 25 Aug 2022 05:11:04 +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 1oR58I-007DWU-2k for linux-arm-kernel@lists.infradead.org; Thu, 25 Aug 2022 05:10:23 +0000 Received: by mail-yw1-x114a.google.com with SMTP id 00721157ae682-335420c7bfeso326534977b3.16 for ; Wed, 24 Aug 2022 22:10:21 -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=EmnP6URNfHv6I0nbxGmg1XJ0KHdi317moIKFVeeAsc8=; b=odzh+413GPIsjI66IJBEHSOJ1TAozjY8/5h10hAgbwXYR+m8+Bq098asyIJO31M6XX FG6XQOp4j4ukN2HsJ06YJmmH7orlAaws2A+dvnD8GzU49lsEM59llnl7vYysAlJjgJkB Z9sSIQCG/bNvPvmJkwVn3TuSSS3HX7RGRbtoLkCPKctFswbbcSHV14tjLpeVjQWTS/3U 74fuO1j9abX4bH4TwtyH1divYl7Kc0o51RcxSyPowqEfdSqwcMMuUC8p7UUGhR3wso3K bgUqyEQlUfxjPBGEj9/3GzXGK/Y/DNJHWiAHHQS6DuztTtwkFMrAa/O5D1XFFaAaC9wU XO+Q== 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=EmnP6URNfHv6I0nbxGmg1XJ0KHdi317moIKFVeeAsc8=; b=Y3XNboGufFJoJdBISzX4G69Rw6D23EUUR6h+UE63kqleT7SWyypdMgmaOQlvi4pWN5 UREg0Mkk7LHofHEROW+i1YMlFjs7ekmPLxNQg59jG/uFTmZKmx5Mw76rS2eP3SaCpGHl MhKxqAXjCFZVgpXdrZztZJCKxtSBZFOESTWrYfNkTODMKZqQIKkjJRIudCTxUjv3H1uu yYfKI4dQ3G/oqTLAfuhtTxKZS3ugMwpeUet2idsBLQeEZLZfkZ5BjDSMHg6D+dYjcNwb sizpBllRmO/pHuWMQm6e5929c3BQG3MgJXrzMy/skrR0slk8ndGr9AFYxhfS7/emmWeS a0pg== X-Gm-Message-State: ACgBeo0MuHvvBfDQ2mE0h5aN/EdPYf80JAvvQPCe13tgmTBPcpndG4is zZtkeSmuiPUmulLFlzPJqzsQHWPI6qM= X-Google-Smtp-Source: AA6agR4ONormzDuDs7YpdVMH6kwTbayc6AXSuIT5cwIOH9liK5R8puxixgYLfHyko+rG1K4Ic3X2+t6qTmc= X-Received: from reijiw-west4.c.googlers.com ([fda3:e722:ac3:cc00:20:ed76:c0a8:aa1]) (user=reijiw job=sendgmr) by 2002:a5b:dd2:0:b0:695:7965:1747 with SMTP id t18-20020a5b0dd2000000b0069579651747mr1981297ybr.415.1661404221149; Wed, 24 Aug 2022 22:10:21 -0700 (PDT) Date: Wed, 24 Aug 2022 22:08:43 -0700 In-Reply-To: <20220825050846.3418868-1-reijiw@google.com> Message-Id: <20220825050846.3418868-7-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 6/9] KVM: arm64: selftests: Change debug_version() to take ID_AA64DFR0_EL1 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_221022_169868_0FB88912 X-CRM114-Status: GOOD ( 10.36 ) 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 Change debug_version() to take the ID_AA64DFR0_EL1 value instead of vcpu as an argument, and change its callsite to read ID_AA64DFR0_EL1 (and pass it to debug_version()). Subsequent patches will reuse the register value in the callsite. Signed-off-by: Reiji Watanabe --- tools/testing/selftests/kvm/aarch64/debug-exceptions.c | 9 ++++----- 1 file changed, 4 insertions(+), 5 deletions(-) diff --git a/tools/testing/selftests/kvm/aarch64/debug-exceptions.c b/tools/testing/selftests/kvm/aarch64/debug-exceptions.c index 17b17359ac41..ab8860e3a9fa 100644 --- a/tools/testing/selftests/kvm/aarch64/debug-exceptions.c +++ b/tools/testing/selftests/kvm/aarch64/debug-exceptions.c @@ -315,11 +315,8 @@ static void guest_svc_handler(struct ex_regs *regs) svc_addr = regs->pc; } -static int debug_version(struct kvm_vcpu *vcpu) +static int debug_version(uint64_t id_aa64dfr0) { - uint64_t id_aa64dfr0; - - vcpu_get_reg(vcpu, KVM_ARM64_SYS_REG(SYS_ID_AA64DFR0_EL1), &id_aa64dfr0); return cpuid_get_ufield(id_aa64dfr0, ID_AA64DFR0_DEBUGVER_SHIFT); } @@ -329,6 +326,7 @@ int main(int argc, char *argv[]) struct kvm_vm *vm; struct ucall uc; int stage; + uint64_t aa64dfr0; vm = vm_create_with_one_vcpu(&vcpu, guest_code); ucall_init(vm, NULL); @@ -336,7 +334,8 @@ int main(int argc, char *argv[]) vm_init_descriptor_tables(vm); vcpu_init_descriptor_tables(vcpu); - __TEST_REQUIRE(debug_version(vcpu) >= 6, + 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, From patchwork Thu Aug 25 05:08:44 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Reiji Watanabe X-Patchwork-Id: 12954207 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 E703BC04AA5 for ; Thu, 25 Aug 2022 05:12: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=tfPbJPwTO0xGfgKuYick5u/zPFOH/KlbPkX3sJemsAI=; b=mEi3gRpyw/nWgifdd05WaBM4vv pyOp0mf1H77mnH2z1l9BHsO37nPmjEqgiaWProkGMg0/n/TCRjXvCi8vOjV3ueu3KUpjB9CPmZxUr lbwBWdMVIOh7d/dXXZ518+rNIzyzKaW+SPpAD3CC+5XEYDzv6GwqbJKiJaHS1wcPld4ePfzHpoVjX 9TdcPwbWPqXERSMBtBxYS4MA2oQw8d1CLkkgcQxNbQMHPN+DkGYOx8tofoQbq0pt4FbEP6IROfM/a 5oqwcGypEipun8GUg/DuxRDKKqW6kczRxN4s0B4d4uzhnEADUsmIAj2IP/1zub2CBZfk+gCMngtgJ +9Y1kRyw==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.94.2 #2 (Red Hat Linux)) id 1oR59X-007EfK-Ik; Thu, 25 Aug 2022 05:11:39 +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 1oR58K-007DVd-Jb for linux-arm-kernel@lists.infradead.org; Thu, 25 Aug 2022 05:10:26 +0000 Received: by mail-yw1-x114a.google.com with SMTP id 00721157ae682-31f5960500bso325528257b3.14 for ; Wed, 24 Aug 2022 22:10:23 -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=kxLW5pptbGK2qbSRXgRbfDO7jFprojIfxGB+rGiWcTI=; b=TTmEHdzamfoOJUzNzm8Oy4Aow3rD92Al5+1R2DqMO26AK3Iz4grwp1RtDbumrf8xkW vsT7LLxK98H4odQgelDUKsgICKCya5ytR7QT6h/NtaLeuyjITnTzHzt1i7NCa/YrNPg+ XOGQ4TkDWJSNJDvJEFcTNGBVtFVRbuCzwm8V//Hgy1+FwzbTR0JjN5lBhfwJZ8sr7qKF H1IErCcBG3gH3cAIkMekez3RKhqDctBKkPP2XKe3uhDpz1NVml3OXTukWPqrUW/W0iaC 8ZTIMJwuOP2mnGj/aKyLUV7FldBwW0xDJY5oWw07wg9ObBsK9Mqahy5glh4Z3NcIMECO tEBw== 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=kxLW5pptbGK2qbSRXgRbfDO7jFprojIfxGB+rGiWcTI=; b=KFy3EhMGR1ZoJM3rxakpXSvcmCNl4mxo31Htvzttqse2jtZfi889TaeCFZM4vSCVFz lpwkDO5gYzrBS6SilOdbW7XJPR1sdMt4YE0/bY1801gbv3CCW+oknHOEdxSNrc9rjypO pB/LFjRV5ZQkfHKpBOO+1FxWCdYcpvNWwVq/BviT0RIU0IXA5r+VyVe3inmIH2RFepUg 6eU8ALDxmJpCsYVOrgdwXY7oYm743b+vgoaxHSVAn6eJSuYWLOqN1ahQWge/wpo5vQCw wKon4eMxQuqt9M6Sx0Zqg+rdu7Rpt+ovV797B/eprjYSGFowSDoBTJ35td5gykJBf9+L ug8A== X-Gm-Message-State: ACgBeo1GFZZeDZqaNdP0pddsVQeETXLejOdbEKgfHq/zzGY7mmrn0dAQ fVbqd7YnlV6pMnRbmBvjCjl8F/9y6MI= X-Google-Smtp-Source: AA6agR4v58RhDrq7Qj6EPYCwT6qLMkj11qqXbbiW+fQsLer7Qtwo+aBr5+w+lCO4r/ZJHQlHtnOL8Wya50c= X-Received: from reijiw-west4.c.googlers.com ([fda3:e722:ac3:cc00:20:ed76:c0a8:aa1]) (user=reijiw job=sendgmr) by 2002:a81:349:0:b0:324:d932:1362 with SMTP id 70-20020a810349000000b00324d9321362mr2226472ywd.281.1661404223276; Wed, 24 Aug 2022 22:10:23 -0700 (PDT) Date: Wed, 24 Aug 2022 22:08:44 -0700 In-Reply-To: <20220825050846.3418868-1-reijiw@google.com> Message-Id: <20220825050846.3418868-8-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 7/9] KVM: arm64: selftests: Add a test case for a linked breakpoint 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_221024_670986_1B074F8B X-CRM114-Status: GOOD ( 14.79 ) 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 doesn't have a test case for a linked breakpoint. Add a test case for the linked breakpoint to the test. Signed-off-by: Reiji Watanabe --- .../selftests/kvm/aarch64/debug-exceptions.c | 59 +++++++++++++++++-- 1 file changed, 55 insertions(+), 4 deletions(-) diff --git a/tools/testing/selftests/kvm/aarch64/debug-exceptions.c b/tools/testing/selftests/kvm/aarch64/debug-exceptions.c index ab8860e3a9fa..9fccfeebccd3 100644 --- a/tools/testing/selftests/kvm/aarch64/debug-exceptions.c +++ b/tools/testing/selftests/kvm/aarch64/debug-exceptions.c @@ -11,6 +11,10 @@ #define DBGBCR_EXEC (0x0 << 3) #define DBGBCR_EL1 (0x1 << 1) #define DBGBCR_E (0x1 << 0) +#define DBGBCR_LBN_SHIFT 16 +#define DBGBCR_BT_SHIFT 20 +#define DBGBCR_BT_ADDR_LINK_CTX (0x1 << DBGBCR_BT_SHIFT) +#define DBGBCR_BT_CTX_LINK (0x3 << DBGBCR_BT_SHIFT) #define DBGWCR_LEN8 (0xff << 5) #define DBGWCR_RD (0x1 << 3) @@ -21,7 +25,7 @@ #define SPSR_D (1 << 9) #define SPSR_SS (1 << 21) -extern unsigned char sw_bp, sw_bp2, hw_bp, hw_bp2, 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, hw_bp_ctx; 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; @@ -103,6 +107,7 @@ static void reset_debug_state(void) isb(); write_sysreg(0, mdscr_el1); + write_sysreg(0, contextidr_el1); /* Reset all bcr/bvr/wcr/wvr registers */ dfr0 = read_sysreg(id_aa64dfr0_el1); @@ -164,6 +169,28 @@ static void install_hw_bp(uint8_t bpn, uint64_t addr) enable_debug_bwp_exception(); } +void install_hw_bp_ctx(uint8_t addr_bp, uint8_t ctx_bp, uint64_t addr, + uint64_t ctx) +{ + uint32_t addr_bcr, ctx_bcr; + + /* Setup a context-aware breakpoint */ + ctx_bcr = DBGBCR_LEN8 | DBGBCR_EXEC | DBGBCR_EL1 | DBGBCR_E | + DBGBCR_BT_CTX_LINK; + write_dbgbcr(ctx_bp, ctx_bcr); + write_dbgbvr(ctx_bp, ctx); + + /* Setup a linked breakpoint (linked to the context-aware breakpoint) */ + addr_bcr = DBGBCR_LEN8 | DBGBCR_EXEC | DBGBCR_EL1 | DBGBCR_E | + DBGBCR_BT_ADDR_LINK_CTX | + ((uint32_t)ctx_bp << DBGBCR_LBN_SHIFT); + write_dbgbcr(addr_bp, addr_bcr); + write_dbgbvr(addr_bp, addr); + isb(); + + enable_debug_bwp_exception(); +} + static void install_ss(void) { uint32_t mdscr; @@ -177,8 +204,10 @@ static void install_ss(void) static volatile char write_data; -static void guest_code(uint8_t bpn, uint8_t wpn) +static void guest_code(uint8_t bpn, uint8_t wpn, uint8_t ctx_bpn) { + uint64_t ctx = 0x1; /* a random context number */ + GUEST_SYNC(0); /* Software-breakpoint */ @@ -281,6 +310,19 @@ static void guest_code(uint8_t bpn, uint8_t wpn) : : : "x0"); GUEST_ASSERT_EQ(ss_addr[0], 0); + /* Linked hardware-breakpoint */ + hw_bp_addr = 0; + reset_debug_state(); + install_hw_bp_ctx(bpn, ctx_bpn, PC(hw_bp_ctx), ctx); + /* Set context id */ + write_sysreg(ctx, contextidr_el1); + isb(); + asm volatile("hw_bp_ctx: nop"); + write_sysreg(0, contextidr_el1); + GUEST_ASSERT_EQ(hw_bp_addr, PC(hw_bp_ctx)); + + GUEST_SYNC(10); + GUEST_DONE(); } @@ -327,6 +369,7 @@ int main(int argc, char *argv[]) struct ucall uc; int stage; uint64_t aa64dfr0; + uint8_t brps; vm = vm_create_with_one_vcpu(&vcpu, guest_code); ucall_init(vm, NULL); @@ -349,8 +392,16 @@ int main(int argc, char *argv[]) vm_install_sync_handler(vm, VECTOR_SYNC_CURRENT, ESR_EC_SVC64, guest_svc_handler); - /* Run tests with breakpoint#0 and watchpoint#0. */ - vcpu_args_set(vcpu, 2, 0, 0); + /* 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); + for (stage = 0; stage < 11; stage++) { vcpu_run(vcpu); From patchwork Thu Aug 25 05:08:45 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Reiji Watanabe X-Patchwork-Id: 12954208 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 02536C04AA5 for ; Thu, 25 Aug 2022 05:13:21 +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=hKFFfod/hutJuenng1vy2G2z4hSjMOcMyJeYePH8w/8=; b=cmkJvhYUU2QbmQCi6Y/57Rmn8z An4ueArfkn0V6+ymYKAQbYl21/YvpSFEFoTMo0yHdtSeL2fvXdTl5NqT0D0r0lHt0+9vcF4jmDBQM 0vSqygDkDtrSn2KNcn/PX1LMWMs6ry+Jk4QMbqd1bIdrh4TWfZmesrxQkggdcPOdAL9ttBmJU7FC7 eaPZAA4gpgGW0SmmZ+piB8p/y5LxC4/a+WO89GyPam6ogYmGm/NDEgKXvJhvguJDkllFMH2/0H5X9 K8pYIAsopVaLXq3rfJqm+6mkHOxGcjjirtLeHpj3oNSDIpzmMBkPRdHvURMsxJf607yqou6K+OoT2 LaVcL+Ug==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.94.2 #2 (Red Hat Linux)) id 1oR5A0-007F59-1U; Thu, 25 Aug 2022 05:12:08 +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 1oR58M-007Dd4-Ca for linux-arm-kernel@lists.infradead.org; Thu, 25 Aug 2022 05:10:27 +0000 Received: by mail-yw1-x114a.google.com with SMTP id 00721157ae682-33daeaa6b8eso35102017b3.7 for ; Wed, 24 Aug 2022 22:10:25 -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=TuEzIR2uESIWnuxyfH1eHFT+9Tcdti9EDHpVvf4j/1Y=; b=FgTwKGkxPoKxP1KMzZgdT1Mj/ysD6A7ddjhiMc4ZMC8VCRZaSS5hI5vKDifgV+39BI wXu770kX27/8AZ9i97GsTq8pOYZk4INErQ8tFX1OSefI1sY6/u/qFMkvHvptqoUSZ6+E k2lJs/C31pUqFQ3ZvzsZ+24EUYugRw3GnYcu5HQmVox/Cz0vKKdoQgbwpTNSHnPtCALC jdCUwq99FBtXx0NYhFVDDz6EMCMTiKpsq48XCFc+vTJZny1B0S5pcoEvPNNMMkhIMRQp eYSEwLumBBkZ8sCvuKlOV0dBHgv9LMAAqIA25/2QSniBAjRoye39JhD06UA5Gm7Ngsy3 IKUQ== 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=TuEzIR2uESIWnuxyfH1eHFT+9Tcdti9EDHpVvf4j/1Y=; b=yvlPaRznain8JZI/4zpAF+lRO6cTInctIdMU6rxAii/EZmrQzv/pK2XaQvikHfjx5U 4R5k9bhnzjz8d1QrSCoquMmATGggD+IXSMVsi9RZGW1mFm0UNsqQbjsGKZX6eKhzU8mU fj4lSKJD19zJgdHwCfL40N2GNlbppSJ/vrvQM58zWC6mEnwSDlHFeD05xSXBncTHp5pB 7Js2J+t/ab3YGYL63ogzIvwnc+c5fhCfxOVQcASyUTbRAbqf2ocGJslwPDVwB4tvJFk1 dvMfybyW9VoKZXTk2sV1AX0B02HetqK/pKjCvofHwaSY8umn24HrKaKEhUQOR+UGpNhq Z8wA== X-Gm-Message-State: ACgBeo2I5XwefcQo1+Z2mPf3wUtrF+JxZpSOgVZlSFPmMXYLVG3kXeLR n9QrJC2lNES//Gsd7vC5DxuyjVTzpUg= X-Google-Smtp-Source: AA6agR7GgsXeBwiRPy64/fTalDKJtX3KknB3Yhd/leHLUxzCnhR5CpkXyRqKF28lF7ZEEPDZE2xp5aqGTPs= X-Received: from reijiw-west4.c.googlers.com ([fda3:e722:ac3:cc00:20:ed76:c0a8:aa1]) (user=reijiw job=sendgmr) by 2002:a05:6902:1101:b0:695:ce92:a857 with SMTP id o1-20020a056902110100b00695ce92a857mr2078061ybu.337.1661404225060; Wed, 24 Aug 2022 22:10:25 -0700 (PDT) Date: Wed, 24 Aug 2022 22:08:45 -0700 In-Reply-To: <20220825050846.3418868-1-reijiw@google.com> Message-Id: <20220825050846.3418868-9-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 8/9] KVM: arm64: selftests: Add a test case for a linked 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_221026_481630_F25F5CBA X-CRM114-Status: GOOD ( 11.53 ) 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 doesn't have a test case for a linked watchpoint. Add a test case for the linked watchpoint to the test. Signed-off-by: Reiji Watanabe --- .../selftests/kvm/aarch64/debug-exceptions.c | 35 +++++++++++++++++++ 1 file changed, 35 insertions(+) diff --git a/tools/testing/selftests/kvm/aarch64/debug-exceptions.c b/tools/testing/selftests/kvm/aarch64/debug-exceptions.c index 9fccfeebccd3..dc94c85bb383 100644 --- a/tools/testing/selftests/kvm/aarch64/debug-exceptions.c +++ b/tools/testing/selftests/kvm/aarch64/debug-exceptions.c @@ -21,6 +21,9 @@ #define DBGWCR_WR (0x2 << 3) #define DBGWCR_EL1 (0x1 << 1) #define DBGWCR_E (0x1 << 0) +#define DBGWCR_LBN_SHIFT 16 +#define DBGWCR_WT_SHIFT 20 +#define DBGWCR_WT_LINK (0x1 << DBGWCR_WT_SHIFT) #define SPSR_D (1 << 9) #define SPSR_SS (1 << 21) @@ -169,6 +172,28 @@ static void install_hw_bp(uint8_t bpn, uint64_t addr) enable_debug_bwp_exception(); } +static void install_wp_ctx(uint8_t addr_wp, uint8_t ctx_bp, uint64_t addr, + uint64_t ctx) +{ + uint32_t wcr; + uint64_t ctx_bcr; + + /* Setup a context-aware breakpoint */ + ctx_bcr = DBGBCR_LEN8 | DBGBCR_EXEC | DBGBCR_EL1 | DBGBCR_E | + DBGBCR_BT_CTX_LINK; + write_dbgbcr(ctx_bp, ctx_bcr); + write_dbgbvr(ctx_bp, ctx); + + /* Setup a linked watchpoint (linked to the context-aware breakpoint) */ + wcr = DBGWCR_LEN8 | DBGWCR_RD | DBGWCR_WR | DBGWCR_EL1 | DBGWCR_E | + DBGWCR_WT_LINK | ((uint32_t)ctx_bp << DBGWCR_LBN_SHIFT); + write_dbgwcr(addr_wp, wcr); + write_dbgwvr(addr_wp, addr); + isb(); + + enable_debug_bwp_exception(); +} + void install_hw_bp_ctx(uint8_t addr_bp, uint8_t ctx_bp, uint64_t addr, uint64_t ctx) { @@ -323,6 +348,16 @@ static void guest_code(uint8_t bpn, uint8_t wpn, uint8_t ctx_bpn) GUEST_SYNC(10); + /* Linked watchpoint */ + reset_debug_state(); + install_wp_ctx(wpn, ctx_bpn, PC(write_data), ctx); + /* Set context id */ + write_sysreg(ctx, contextidr_el1); + isb(); + write_data = 'x'; + GUEST_ASSERT_EQ(write_data, 'x'); + GUEST_ASSERT_EQ(wp_data_addr, PC(write_data)); + GUEST_DONE(); } 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; }