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");