From patchwork Thu Oct 20 05:41:55 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Reiji Watanabe X-Patchwork-Id: 13012630 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 95298C43217 for ; Thu, 20 Oct 2022 05:43:57 +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=1Yy9RRVQKoi1GqEPd6BtGKuvftwF6TdB84znjrUkILw=; b=5G9iQIrScatPt5YhmmAp/ZbgPz oh68Gs0CvppjX/Erny4y1egDcrriw0Wje7lM4JK2PB7ux7PdKJQa0pcgHPWiyVzHitILSA49fSfs4 FJaVHc4AvklhUe6JrzFVLr7aLwakW8VElBacoC6ECj0ebDBriiuti7gIz96tIHLCpwcljEkldAEaA eXRuwO5y5l59PuSmbejUibB950T+v2K5KH05BNTUjdxNXsYUt5+1H4pX+Jl89KbUDKS2wd/xvf6YO G5TMZqGXJJhbBLtWo8KyhiTuUE35P29PoDxXttPkK6Km7hRK77wgDorsec4wDooCJQo8B11NL+7HL XkvwWRKA==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.94.2 #2 (Red Hat Linux)) id 1olOKR-00AUZf-GK; Thu, 20 Oct 2022 05:42:51 +0000 Received: from mail-yb1-xb49.google.com ([2607:f8b0:4864:20::b49]) by bombadil.infradead.org with esmtps (Exim 4.94.2 #2 (Red Hat Linux)) id 1olOKO-00AUWz-Ck for linux-arm-kernel@lists.infradead.org; Thu, 20 Oct 2022 05:42:49 +0000 Received: by mail-yb1-xb49.google.com with SMTP id 130-20020a251188000000b006be249d0a70so18203563ybr.2 for ; Wed, 19 Oct 2022 22:42:45 -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=ELzAVn+3sNc+4loFg06+kDTn2r7oBUPNaJZquHZJGM8=; b=JHe9BhP8WxnUbibz6mt6YrXKaJ8YGE5HpO4NBAJasDjfzX6DH+FcWz/XA8i3DPgO+p IdhKCFDnzk5HbJ3oNT6RDfyg0Z9C0EeQ/XxJ9EKICgTXNawqyOk+vgb5hFo6UQCx8nVK ZKTsmXkj0jLCeWzC+WMWjrRGS8WDAy/749MHc14vQ5evsPc2NXLmx8VNJ0rbBnvb2/Xy 5zI6/pvcBwkVjN6NACbeFpP/E8FMP+cwvZJ0Ovuy025NxlUFlKNnp01rl1mOEO7w90LG Gr+BX+BLdl8IPeROXbXAfLtkFLRqlwTO2L54IxyzvTlT6LqkZffO7mKaveT3ZeinuHqe vENw== 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=ELzAVn+3sNc+4loFg06+kDTn2r7oBUPNaJZquHZJGM8=; b=qAcI+P6qQrjf3wSMM7wTyFlDAIqa7++ZChK+A/uS68UEM9Nb2bpRXevdzT0rrILzqr pchOR0T2G9Y57h/C1WneIMG+zb3UU3RV5DNCWz8qll5+ysXhyHWmlm5mWt9ryCTUydkc 3wnCMOSKSWN74Gd90NFBOzF/XLCXUNWoe6S0iTd59jLzrB+pJdLqs8A/yGc9yAkqbp5/ gSVTlE7EJsq72uwCFcGDhtmZ7Pk0UTzwUDMl+Lq8TVsOJvqidTD6pXw/LZ/+LmSvqj9a wY85Op64Bs3Eillw3bRRR/ieTIyIKfhj59iwXcefQk7mk3KIo57eGhWu3ebuwDa9y1YJ pyuQ== X-Gm-Message-State: ACrzQf35aoovqO8AVZXIPYQuIll8S06ClWVE46Lhhk1z19TuFMzbvyv5 CYOVYhh6EHMEI72a4BHEZpyQ/JJ/yNs= X-Google-Smtp-Source: AMsMyM40Wdm+aeMOq5/+3bxZYEWlyCvjAW5HTHRrIls1sP9psLlqv/cFoMirmbh8Ju7nrRwXqbWzEiB5zBY= X-Received: from reijiw-west4.c.googlers.com ([fda3:e722:ac3:cc00:20:ed76:c0a8:aa1]) (user=reijiw job=sendgmr) by 2002:a0d:eb88:0:b0:367:284a:a4a with SMTP id u130-20020a0deb88000000b00367284a0a4amr5163460ywe.282.1666244564673; Wed, 19 Oct 2022 22:42:44 -0700 (PDT) Date: Wed, 19 Oct 2022 22:41:55 -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-3-reijiw@google.com> Subject: [PATCH v2 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-20221019_224248_451915_EE895BF5 X-CRM114-Status: GOOD ( 10.83 ) 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. No functional change intended. 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 3808d3d75055..d9884907fe87 100644 --- a/tools/testing/selftests/kvm/aarch64/debug-exceptions.c +++ b/tools/testing/selftests/kvm/aarch64/debug-exceptions.c @@ -30,6 +30,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"); @@ -61,8 +124,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"); @@ -78,8 +142,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");