From patchwork Thu Oct 20 05:42:01 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Reiji Watanabe X-Patchwork-Id: 13012636 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 AFE3CC433FE for ; Thu, 20 Oct 2022 05:45:31 +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:Message-ID: References:Mime-Version: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=9/SBL4KNuwzJ7M5jWJjwd0fQDgRTz2eWBWgqvhFdZSs=; b=CxQpbXdoWFwEP3kyh5qLvfyyOe ZyaxpdJvBZWP+XvKHwjvPcfVxrTHGogPx/cKOFNlYJYGXx3SQwy2ECcNLe+OruQyn7lMiklUvI0B6 ilMM45m7tGLmGdyrVL7WBqwG7AcjcYu4S5Uk06YXLglM9eAzSmL80u0mJEn6qGHRE/fE3Qgwy2sre lB62dJhVDFp5bF0ekRf++wkHpjPGGVt6Z6qNICwn8PEJptUdSvznPjIqzxye65fWC4nCs6WOU5Efp m0GTNDBpnYfU0K5nQzqX4FQcuNGm7sRxQr80xOBVZfeFQ32VUxwk0JaHHgXLBYfvoeqGjGt9+UbQk cABXH5gg==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.94.2 #2 (Red Hat Linux)) id 1olOM3-00AXGj-BX; Thu, 20 Oct 2022 05:44:31 +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 1olOLO-00AW2b-1g for linux-arm-kernel@lists.infradead.org; Thu, 20 Oct 2022 05:43:51 +0000 Received: by mail-pj1-x104a.google.com with SMTP id gn9-20020a17090ac78900b0020d7a817d36so8188075pjb.2 for ; Wed, 19 Oct 2022 22:43:48 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20210112; h=cc:to:from:subject:message-id:references:mime-version:in-reply-to :date:from:to:cc:subject:date:message-id:reply-to; bh=NTH7ZmIDUvfRqYyd1HhBU5CIbrwUrGIrg8Vkup78EQQ=; b=a0kob/6IV3hX8wveVUZp8aIkDTHPSkKD5x0boK7exvWYmVqS1xKXjC980frftI1iB8 OWCsn1M7ioegFzfpZDpYLhsw7YxdRjT1mqJh6jP7+GD6gBX65QrnaGUXiiGWxjhSn2aS /+R3vDIVC5QbrkbrkeoXpCeR63kcHlllzNsasi2HfB9dkxUIrG4HllTXWAz7kLz5flMg PKkcNWAIF9qF2dNNuqMTKpGOzyb4SJKBkGqu59mOkKQVVJMIiug52s+14wVOER9MNH0R LNFZfjxYmtfAvlWRsxg/hxtMqa48+J7IPUDMYSOQEcdhdSX7ZLvH6BjAXQCbljrXZYqA pyQg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=cc:to:from:subject:message-id:references:mime-version:in-reply-to :date:x-gm-message-state:from:to:cc:subject:date:message-id:reply-to; bh=NTH7ZmIDUvfRqYyd1HhBU5CIbrwUrGIrg8Vkup78EQQ=; b=vqP8TLRDIRNfbrrcqlzI6AJ1CkYR5LKh188fGh1RJ9Z3Z2YslZ5S+ynjK0Ik4j2Bsf qI471miBfSOQTiBW9c0P3D+rJkthdkC9DQXgIfqpnzujDRfHSGXfF1GF2HxMVfe4iWZt aotObR3W4Mmi8/aM561oTVMhDpmRlJ/4XhblJ0Qcua1YIWaO4fcqhWyTFCpacxPUlIzr 2S3IzChrs7uCvKbfYe34jAkGvJntlEhzDF4rVmwgnj1vZux8eazY1WEkIdcanUuLRvi3 r99SS8JCJ0PIEblNSmFZUXZmsng823Wjv0JZI+G9YcFpjxPKuFmVm85JnFNcPjRSDO9i L1tg== X-Gm-Message-State: ACrzQf3/nOt3Mi9eIfDO0Yx+InmdxkLqUoZWqdjTyHQtssKbNdDufHPC tqcESWX0Kh2qguHo4EO3zN70xyD3y8k= X-Google-Smtp-Source: AMsMyM7HKrCTV8qQjJ+AeuKopjnwPGTiQp5PNWWQkgWncAh69Zqd6D1WMZdPZsMDLEvCA6w055Dg1d+ZtUw= X-Received: from reijiw-west4.c.googlers.com ([fda3:e722:ac3:cc00:20:ed76:c0a8:aa1]) (user=reijiw job=sendgmr) by 2002:a17:902:d2cc:b0:182:d901:5d28 with SMTP id n12-20020a170902d2cc00b00182d9015d28mr12606746plc.142.1666244628304; Wed, 19 Oct 2022 22:43:48 -0700 (PDT) Date: Wed, 19 Oct 2022 22:42:01 -0700 In-Reply-To: <20221020054202.2119018-1-reijiw@google.com> Mime-Version: 1.0 References: <20221020054202.2119018-1-reijiw@google.com> X-Mailer: git-send-email 2.38.0.413.g74048e4d9e-goog Message-ID: <20221020054202.2119018-9-reijiw@google.com> Subject: [PATCH v2 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-20221019_224350_124299_2F1118F3 X-CRM114-Status: GOOD ( 11.94 ) 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. The new test case uses the highest numbered context-aware breakpoint (for Context ID match), and the watchpoint#0, which is linked to the context-aware breakpoint. 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 362e7668a978..73a95e6b345e 100644 --- a/tools/testing/selftests/kvm/aarch64/debug-exceptions.c +++ b/tools/testing/selftests/kvm/aarch64/debug-exceptions.c @@ -22,6 +22,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) @@ -171,6 +174,28 @@ static void install_hw_bp(uint8_t bpn, uint64_t addr) enable_monitor_debug_exceptions(); } +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 for Linked Context ID Match */ + 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_monitor_debug_exceptions(); +} + void install_hw_bp_ctx(uint8_t addr_bp, uint8_t ctx_bp, uint64_t addr, uint64_t ctx) { @@ -306,6 +331,16 @@ static void guest_code(uint8_t bpn, uint8_t wpn, uint8_t ctx_bpn) write_sysreg(0, contextidr_el1); GUEST_ASSERT_EQ(hw_bp_addr, PC(hw_bp_ctx)); + /* 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(); }