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(); }