From patchwork Thu Oct 20 05:41:54 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Reiji Watanabe X-Patchwork-Id: 13012629 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 2DEC9C433FE for ; Thu, 20 Oct 2022 05:43:38 +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=k2WnM97hH9WPhfkYgZV5wz+tiLIsOfQNLTxXdcK24oI=; b=v+7aIUOw1IVASBYiXrji05Z9KM F1qHzHUOdzUh0WIt63TRXhzCxzEAUHvSh8v4SpvtbyMdBYQl9uDJDsBWyX2UlgzuV7Wtlv2BOul1b DCakAxAqORKn4MbMgE1mbIUJ0gvsz/EJThWodCFqOUwR158J5adeXz8/taPRRMliVUGQGDxZhrlqD G5D3nQYkjrsyD+SxwNvTaUXlMttHwkQiLUaBn+L8mtUfkqPQD7yw+YilVjz+5fqZtefcppMm4jirI tsj7WFZrQ24jN2zashgprb5ECVwLtCP58YbAaDrA/9OybwCE6DKEmZD5AoLGkHZG9B/8KwLj+ASg2 OkZNc2fA==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.94.2 #2 (Red Hat Linux)) id 1olOK8-00AUHt-SH; Thu, 20 Oct 2022 05:42:33 +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 1olOK6-00AU4q-DO for linux-arm-kernel@lists.infradead.org; Thu, 20 Oct 2022 05:42:31 +0000 Received: by mail-yw1-x1149.google.com with SMTP id 00721157ae682-368036d93abso16725547b3.18 for ; Wed, 19 Oct 2022 22:42:28 -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=OtsUIATys8SkfvMgOGJq0e0j5nN53CM4H2CIbL5rRi0=; b=ZX+JU8/V1nRnIZUBPbKK0qGTCivJ3Y9kvTcZGWISj2umve+Lkc1zeEUrboyT0Inj7Y 346h2aTSgGDQ76woN32t78HuTwfn28egkrPJcJ4zRgPNIdga8G0bBC3+GBsZiNMRzufB aL7kC2Uc2v79AmFgOrlg56nnJTlo5YnORZPdbS/hpakZlDVKuORnYIKxe3FKAy1g3xiK DkdHNol0fH/Ag+E+revtePM+AKUrVz+D6EtTvBr2kf8AedsI6W2nk6/QsuhbdmMxG5j1 xbuN9wr6PpMOqgof1JPBF5A+cRj8YX+X4pxuECrOTMtLYHiDN+g7fJj2HzVHqMk3J4Ln nLLA== 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=OtsUIATys8SkfvMgOGJq0e0j5nN53CM4H2CIbL5rRi0=; b=4qpNCamj55IrJvnVxFEh7JqfPgkmme9Bz/nXvgoD7heJx13UBZSCNJs1uVrbHfFTc2 9/i8qxdHyb+lSEHFPCoGl27BIx6CJt6FLda6I08MxYHaxDE7VD60im1ZAKav0zlrur74 6Af5TfCn8SIsDAEdgmuZgqajEOjLyej0y0k8VT9cMHUwwftRK0yzkwBzSA3uzDlb9lKf JPKPQ2AC8zAtu6c0mP/usP0l+omMDtiaUb4lWJgt6xd0ulCUeAJ9kD1ZBPpJezL5wOUf eZ/cjMNO/Eso6I9G8VKuAkeEFP7/T5ZHn8SSj520bLeOxQOoycY/bR5aZabCyxWHDf0t IX5A== X-Gm-Message-State: ACrzQf2PgE/ayltwjA+Y9+NBnN2dEl6edGYJIWUWV/kLi7CWyKtuSf6t PpvY1Lr+u+U4kVS77HsL6dLceML2J3A= X-Google-Smtp-Source: AMsMyM62d9qUBEI9Szy5XvNyeaXoCZg+BAERgrHl1ogyZK/rKzQd7G+6eh0cX2mqgOijUie19nTObinLjW4= X-Received: from reijiw-west4.c.googlers.com ([fda3:e722:ac3:cc00:20:ed76:c0a8:aa1]) (user=reijiw job=sendgmr) by 2002:a25:e705:0:b0:6ca:6ae:e194 with SMTP id e5-20020a25e705000000b006ca06aee194mr4508847ybh.113.1666244547836; Wed, 19 Oct 2022 22:42:27 -0700 (PDT) Date: Wed, 19 Oct 2022 22:41:54 -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-2-reijiw@google.com> Subject: [PATCH v2 1/9] KVM: arm64: selftests: Use FIELD_GET() to extract ID register fields 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_224230_474343_1DD2FD97 X-CRM114-Status: GOOD ( 11.37 ) 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 Use FIELD_GET() macro to extract ID register fields for existing aarch64 selftests code. No functional change intended. Signed-off-by: Reiji Watanabe Reviewed-by: Oliver Upton --- tools/testing/selftests/kvm/aarch64/aarch32_id_regs.c | 3 ++- tools/testing/selftests/kvm/aarch64/debug-exceptions.c | 3 ++- tools/testing/selftests/kvm/lib/aarch64/processor.c | 7 ++++--- 3 files changed, 8 insertions(+), 5 deletions(-) diff --git a/tools/testing/selftests/kvm/aarch64/aarch32_id_regs.c b/tools/testing/selftests/kvm/aarch64/aarch32_id_regs.c index 6f9c1f19c7f6..b6a5e8861b35 100644 --- a/tools/testing/selftests/kvm/aarch64/aarch32_id_regs.c +++ b/tools/testing/selftests/kvm/aarch64/aarch32_id_regs.c @@ -13,6 +13,7 @@ #include "kvm_util.h" #include "processor.h" #include "test_util.h" +#include #define BAD_ID_REG_VAL 0x1badc0deul @@ -145,7 +146,7 @@ static bool vcpu_aarch64_only(struct kvm_vcpu *vcpu) vcpu_get_reg(vcpu, KVM_ARM64_SYS_REG(SYS_ID_AA64PFR0_EL1), &val); - el0 = (val & ARM64_FEATURE_MASK(ID_AA64PFR0_EL0)) >> ID_AA64PFR0_EL0_SHIFT; + el0 = FIELD_GET(ARM64_FEATURE_MASK(ID_AA64PFR0_EL0), val); return el0 == ID_AA64PFR0_ELx_64BIT_ONLY; } diff --git a/tools/testing/selftests/kvm/aarch64/debug-exceptions.c b/tools/testing/selftests/kvm/aarch64/debug-exceptions.c index 947bd201435c..3808d3d75055 100644 --- a/tools/testing/selftests/kvm/aarch64/debug-exceptions.c +++ b/tools/testing/selftests/kvm/aarch64/debug-exceptions.c @@ -2,6 +2,7 @@ #include #include #include +#include #define MDSCR_KDE (1 << 13) #define MDSCR_MDE (1 << 15) @@ -284,7 +285,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 FIELD_GET(ARM64_FEATURE_MASK(ID_AA64DFR0_DEBUGVER), id_aa64dfr0); } static void test_guest_debug_exceptions(void) diff --git a/tools/testing/selftests/kvm/lib/aarch64/processor.c b/tools/testing/selftests/kvm/lib/aarch64/processor.c index 6f5551368944..7c96b931edd5 100644 --- a/tools/testing/selftests/kvm/lib/aarch64/processor.c +++ b/tools/testing/selftests/kvm/lib/aarch64/processor.c @@ -11,6 +11,7 @@ #include "guest_modes.h" #include "kvm_util.h" #include "processor.h" +#include #define DEFAULT_ARM64_GUEST_STACK_VADDR_MIN 0xac0000 @@ -486,9 +487,9 @@ void aarch64_get_supported_page_sizes(uint32_t ipa, err = ioctl(vcpu_fd, KVM_GET_ONE_REG, ®); TEST_ASSERT(err == 0, KVM_IOCTL_ERROR(KVM_GET_ONE_REG, vcpu_fd)); - *ps4k = ((val >> 28) & 0xf) != 0xf; - *ps64k = ((val >> 24) & 0xf) == 0; - *ps16k = ((val >> 20) & 0xf) != 0; + *ps4k = FIELD_GET(ARM64_FEATURE_MASK(ID_AA64MMFR0_TGRAN4), val) != 0xf; + *ps64k = FIELD_GET(ARM64_FEATURE_MASK(ID_AA64MMFR0_TGRAN64), val) == 0; + *ps16k = FIELD_GET(ARM64_FEATURE_MASK(ID_AA64MMFR0_TGRAN16), val) != 0; close(vcpu_fd); close(vm_fd); 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"); From patchwork Thu Oct 20 05:41:56 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Reiji Watanabe X-Patchwork-Id: 13012631 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 193ADC433FE for ; Thu, 20 Oct 2022 05:44:05 +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=49lk5lpam9+qirXj4lkKrYF6EYiKZehWPpyc6j5qmz8=; b=h0JewQFMYYWuuZYJmzrw9m8DDj Dvi4UVsXfYD9/3qrvk+0Yf6TLi6T/um9HBnUr+XtdEuzUtTI4iMxJIHYy8WbIvJD3noZTUtdddkp9 JqN8b45NCfP3QS8J/EexpnAyxOrikxm8xohe9hE2LWIWKAsFm2w0mUerFM9VJmOvxJI5KB438c6M8 W1tfXfgW4EFgc+Vz+1ue4rN3Omsy318GZbmcjerL1YBqtk/APAgXZ4Icc4X7BPKdvvVFTETMu7Ooi JAodrLPEnlYb6bQlbFiO8zUcDRovmAFkxXQzcKANAMCuGIKbcbD3SMeNKFXsNpPMOl9GBfO0yXc6e 4Y1lWlbA==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.94.2 #2 (Red Hat Linux)) id 1olOKa-00AUnj-9T; Thu, 20 Oct 2022 05:43:00 +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 1olOKW-00AUf8-OE for linux-arm-kernel@lists.infradead.org; Thu, 20 Oct 2022 05:42:58 +0000 Received: by mail-yb1-xb49.google.com with SMTP id g15-20020a25af8f000000b006bcad4bf46aso18326822ybh.19 for ; Wed, 19 Oct 2022 22:42:55 -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=qGPUfNXbDXq8tVpmh3iXBlsoXoLe+lb9ybKX9Ouotxs=; b=fam3UQuvRDuo6oBP8SRNcDAciBNKVKz4/fFVWts2VwMESRtauKi37VbcrTWOZjxpGX y7vkWeI+JuaZLGgSBbADMD95DBSHeTN8COMYJiR/JhGqRr/MXCjI0hjQ40V7f+Rss4+6 9tW2Q4X356WVRbUSKNmnn/gKdvrjK8u4NayWOu6nxedkz+nOLfQuQw2BoLc7VFHeqUbA p7G0sZvOlyDxYS+wuQ34OcckGjJ3znkGxxbKkwsLtQZ3tnuucwKFNOoobWeGXU3bbygt w7JZ17Gzdc/dm6BDfZqiCnl+njnMkRCaMoqali1iPAqMPQMdCZsZXDbe7jy8E4gUGxVc qkjA== 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=qGPUfNXbDXq8tVpmh3iXBlsoXoLe+lb9ybKX9Ouotxs=; b=YjNUBIXqnkuh3+yyTcNsWi97BeJqa8qQRLY8/6ya1BrizqBjnVssMA4OaUNSP3RbEJ UDalmqWguFuwoENVG9WeGK9F+M9XUrHGLM+SoCab6wN9iy/rC5vpJGC7O4HKPuoeicJ8 FZxsBQyHw2osObFI82M7z5hmaSduE3IkTta537ZzUT4jN+gMYQF0VcBU2690ovVavH8z PMWZ7zQvabIFoM7KFe0hG/+JE00hG2fdknw0AIsDNCg86dZqC46aGEon9QGwYLtIzZ4Z lxdDOrheXmKY8VGG4WppitGCuOSIVNNCnzqPlTmtSbtIH9K/Q/UpZdizyf5ahWr1kLm5 VcRQ== X-Gm-Message-State: ACrzQf2HJmkxcldKV85MW9wRy9VAzXkoqswjEJAY2S/H/f4c8S2i4Jjy QivC7xm0h/HhVt82wmLyyv6QRbsHCJA= X-Google-Smtp-Source: AMsMyM75m4E9sVLnRu9y7rmR0yLBR2tNjSIyrcpolvmnOh5DeGKR1WpAeFmXIgNIxR/XfGes3CkkIHTtWDs= X-Received: from reijiw-west4.c.googlers.com ([fda3:e722:ac3:cc00:20:ed76:c0a8:aa1]) (user=reijiw job=sendgmr) by 2002:a25:5f45:0:b0:6c4:46b3:6f6d with SMTP id h5-20020a255f45000000b006c446b36f6dmr9081488ybm.62.1666244575457; Wed, 19 Oct 2022 22:42:55 -0700 (PDT) Date: Wed, 19 Oct 2022 22:41:56 -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-4-reijiw@google.com> Subject: [PATCH v2 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-20221019_224256_813992_7BA6EC72 X-CRM114-Status: GOOD ( 13.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 Remove the hard-coded {break,watch}point #0 from the guest_code() in debug-exceptions to allow {break,watch}point number to be specified. Change reset_debug_state() to zeroing all dbg{b,w}{c,v}r_el0 registers so that guest_code() can use the function to reset those registers even when non-zero {break,watch}points are specified for guest_code(). Subsequent patches will add test cases for non-zero {break,watch}points. Signed-off-by: Reiji Watanabe Reviewed-by: Ricardo Koller Reviewed-by: Oliver Upton --- .../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 d9884907fe87..608a6c8db9a2 100644 --- a/tools/testing/selftests/kvm/aarch64/debug-exceptions.c +++ b/tools/testing/selftests/kvm/aarch64/debug-exceptions.c @@ -95,6 +95,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); @@ -102,11 +105,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 = FIELD_GET(ARM64_FEATURE_MASK(ID_AA64DFR0_BRPS), dfr0); + for (i = 0; i <= brps; i++) { + write_dbgbcr(i, 0); + write_dbgbvr(i, 0); + } + wrps = FIELD_GET(ARM64_FEATURE_MASK(ID_AA64DFR0_WRPS), dfr0); + for (i = 0; i <= wrps; i++) { + write_dbgwcr(i, 0); + write_dbgwvr(i, 0); + } + isb(); } @@ -118,14 +130,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(); @@ -136,14 +148,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"); @@ -166,7 +178,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); @@ -179,7 +191,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)); @@ -187,7 +199,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); @@ -196,7 +208,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)); @@ -205,7 +217,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)); @@ -239,7 +251,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); @@ -251,7 +263,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); @@ -376,6 +388,8 @@ static void test_guest_debug_exceptions(void) 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 Oct 20 05:41:57 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Reiji Watanabe X-Patchwork-Id: 13012632 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 E45A6C4332F for ; Thu, 20 Oct 2022 05:44:20 +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=MU3VQIy8SGW2Q2/vB3LN7lOCxygM6g8u8rV0MNF70yU=; b=R1u4zxylwx04c+xy3n64JSTsRY poqdGcI3fJuyaY3P62RFrDyVwCiS4Ac4kTsF4ZINhOSOPqBvFIvOjcNDBFZgzlgJBff2Sbp+e4mJ1 PMNWounZUknQ70hEoPMYl66KtN87ZV/r3Rg1LfZbzQK2GN3RWdgseFx+agF15mRipsaA2HUZcUEE8 zlBMlBByVj5Kx90VteLwH7QjJQtZDrl9/WZhk/F8O0kvNnWG65ClervvZJ5V/XDYNzqYfmis3H6+9 OlLEgsLl4rTioi+k/c0PBPpG+pZfCtGZhWm0BvHb6tXtzHtE/IyGJ12JaobDnMy83EaqGGBFF2a2f l3lmkTmA==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.94.2 #2 (Red Hat Linux)) id 1olOKq-00AVBB-QK; Thu, 20 Oct 2022 05:43:17 +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 1olOKm-00AV34-Sg for linux-arm-kernel@lists.infradead.org; Thu, 20 Oct 2022 05:43:14 +0000 Received: by mail-yw1-x1149.google.com with SMTP id 00721157ae682-367f94b9b16so17887207b3.11 for ; Wed, 19 Oct 2022 22:43:11 -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=gJ7DW6FMrS3/XjKR3IUADDixPsWjRSTHpU4QIywCQT0=; b=kGndETIJMFAPsM6o9M6DaJUd1eiJ2R4UMKlgOyP1fNzxbCIVhSLbX7CnVkqS0nZlgD qkckUwjazjcZLM/YkMuwJNmj1ry2kxAjdem3B0xhMr2Dp4mF/14rIR7QQKqF48mU8mB8 DcVOolzBRorJXy4aurbFEdEk/2+PPc1mT16TphLnIg/nGPjf1VTt5E1w2sdOQK4gJFWK SWfUUVygx2JxiN+W1eCfC/6ejAbDk16p/xlU+QRxcN9+DW5mPw4pCt5m2rJjzODbwnTl IPW0r6GYVCllZBAnh/B7sQDg2fWC80wwFFwvtnm6wbVWdEwS7OpZC3IggwH4D5drvjZp wY9Q== 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=gJ7DW6FMrS3/XjKR3IUADDixPsWjRSTHpU4QIywCQT0=; b=jUkCib9td1Xo6CRU3M9V8YcWMF2r0KdArcQ29eCmL/OXZeFr+Ikv69WpOTZwH+LYZ1 mNC8rFwsceqwE9WliGpqQP0yiOnDbMNZZpIwsBdXi0E3MaJL8zKvKn5v4cKxnipBySfE W3rB7j46ah+faIUCKbgFello4P63948n335UKJ0N6OXW3odqVq1mnBhGBw5hbaLmuKw4 xFFuzJBGfxabRXSgU+2e/RZNeizoy4Fb4uIjDD6foRzwy8JnpHSWdAZ2vYYIDqAvZLLs 8xwpzoe+oefpJopIfbsV8Boc/llcGrcq7CgHv++v2Aff6Av9TBnDXSC2keodWhJKgFE9 L+cQ== X-Gm-Message-State: ACrzQf3n2T4Z+KNlUPLKxCxPl2IzPon8fJhgxtWvFMWmXuTdpJ+leoFi r9uAz9oDivbTDTfQAEifyM7SdFMfzPw= X-Google-Smtp-Source: AMsMyM5cafI3oKmmNqdU3WwdsV2NsJ9CGbFSB+7QFWMTaiHhqL6V6IVmTaXwI0KJcvCCmksQc05HdIvzMqg= X-Received: from reijiw-west4.c.googlers.com ([fda3:e722:ac3:cc00:20:ed76:c0a8:aa1]) (user=reijiw job=sendgmr) by 2002:a25:7cc7:0:b0:6ca:3ba9:a1b8 with SMTP id x190-20020a257cc7000000b006ca3ba9a1b8mr438557ybc.206.1666244591287; Wed, 19 Oct 2022 22:43:11 -0700 (PDT) Date: Wed, 19 Oct 2022 22:41:57 -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-5-reijiw@google.com> Subject: [PATCH v2 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-20221019_224312_948366_32276CF5 X-CRM114-Status: UNSURE ( 9.16 ) 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. No functional change intended. Signed-off-by: Reiji Watanabe Reviewed-by: Ricardo Koller Reviewed-by: Oliver Upton --- .../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 608a6c8db9a2..0c237022f4d3 100644 --- a/tools/testing/selftests/kvm/aarch64/debug-exceptions.c +++ b/tools/testing/selftests/kvm/aarch64/debug-exceptions.c @@ -130,10 +130,20 @@ static void enable_os_lock(void) GUEST_ASSERT(read_sysreg(oslsr_el1) & 2); } +static void enable_monitor_debug_exceptions(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); @@ -141,28 +151,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_monitor_debug_exceptions(); } 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_monitor_debug_exceptions(); } static void install_ss(void) From patchwork Thu Oct 20 05:41:58 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Reiji Watanabe X-Patchwork-Id: 13012633 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 1401AC433FE for ; Thu, 20 Oct 2022 05:44:39 +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=PkO2llwfXDb1B7iLDZWBkwII3FqNmX1rsudY3jqSWyU=; b=s2eg/TT2ueP8QD1z1/OqX8o75f dYyFctxqNbI/zhIGz3yPe3PyosgMSId9XuO3WmaozY4vDgK7SxwaAm3PaeHOOx266N8iKFz7aGWjy GlFIcNAAN2iWu/vvMzMgM0yBRZNYQtsBG6dScTRYQw78KWbzAKZaEOeZTkLGREPgXFBhfbjJGaA2o 6OrkMV1AEcadZ0oT6lKVeK331b/O8m9NfJe9iFA0wOdlprKXz1ZbFxHojEwKAfD1TJun7Bn9rnJpk Q0KAYPmwF5ABEPUfBZH5vQgZk/pcjaqENCge21PwWs1rQra3zAcxfZL8OPBvR1Vg8/2k3DTgZdm12 o5sYSGvQ==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.94.2 #2 (Red Hat Linux)) id 1olOL9-00AVWt-0O; Thu, 20 Oct 2022 05:43:35 +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 1olOKy-00AVNT-0R for linux-arm-kernel@lists.infradead.org; Thu, 20 Oct 2022 05:43:25 +0000 Received: by mail-yb1-xb49.google.com with SMTP id i142-20020a25d194000000b006ca2a4b5abcso1070396ybg.3 for ; Wed, 19 Oct 2022 22:43:22 -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=sqtie0nDjMeT2v2Cqd738nkIEQS32Gq8MxuRjr1xwVc=; b=PtyaiWR4WGo4SesPD4NhgOaa8i/QN8S5fPQK2di+xNIZlE93h/OJC7MOpeng7dh/dP 2S6hIhiV16OlKK4bYhadwIYORTNSEwjTF6GlWdeYK5v8KeGgItAMuUXnOUErgzCXNR7K YX/mcwhTneKQfRM/Rz9yKqgqvgjCJSGZMeIUXQPs8ZsAUCb0foNXOLmSwVN7pj5pfemw aMEoIZHxbLXPrbWr9F9zj+3dOCexZpmrDWCQJUCKBuljkl5TBbp6u6oej73BlteSsRar BytFebUf2GqbMatnT88RXuvvqwUh+W1RlU4PQa/maA3ZDUfAcDR3O47hli6qzCQ/+ho5 ZDXg== 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=sqtie0nDjMeT2v2Cqd738nkIEQS32Gq8MxuRjr1xwVc=; b=SC5tZDsvuIB2u/yr5D3MAZdhFWuo0xKEpsWZsn2ag9SnyEHfBnZO1ueKDHHywYQrnM b5W/7YaJgnHqMidH2fj/WbnORvM+qCnV6Bfq0h9blDJTrmNn6USpz+xKBBpbQDn+91Si vA5cSCj2iuwA4MEAcjzKSAMrMmex8R6cDA4YhYUTObDrLWTKj/2M/6z8vSA9UAJKWxii 1TNGKaWimaKnYl4H14IBdHLgKjHvmjUeePEVUJ3Gq6cuX2ilmbaSa4z8HBrEL/nzC/r4 CBDYs6ZA1Snx8FHqQHVPRCkc3puq2J/vQhj3TSu34o1uDQw7Std1OcZDoUXSy+x+vbsF L6eg== X-Gm-Message-State: ACrzQf0sD5CIWULLcrK57vaVnBfWBq8IFusdIjHaYyra/awlw4oBs6fO /DuGA6Z+2L8+tLo9+aNO5AnNFIvwAyw= X-Google-Smtp-Source: AMsMyM4Fqo7ndlNYZ4mVtqdSOrn1nGG2kziWEsfTG2Zq//6tftpIR+zQz7Zzf03dgoXXhtbMT8qgEgXk3M0= X-Received: from reijiw-west4.c.googlers.com ([fda3:e722:ac3:cc00:20:ed76:c0a8:aa1]) (user=reijiw job=sendgmr) by 2002:a25:2845:0:b0:6c3:b4c4:9cef with SMTP id o66-20020a252845000000b006c3b4c49cefmr9654314ybo.443.1666244602382; Wed, 19 Oct 2022 22:43:22 -0700 (PDT) Date: Wed, 19 Oct 2022 22:41:58 -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-6-reijiw@google.com> Subject: [PATCH v2 5/9] KVM: arm64: selftests: Stop unnecessary test stage tracking of 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_224324_089277_756A6557 X-CRM114-Status: GOOD ( 13.24 ) 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, debug-exceptions test unnecessarily tracks some test stages using GUEST_SYNC(). The code for it needs to be updated as test cases are added or removed. Stop doing the unnecessary stage tracking, as they are not so useful and are a bit pain to maintain. Signed-off-by: Reiji Watanabe Reviewed-by: Oliver Upton --- .../selftests/kvm/aarch64/debug-exceptions.c | 46 ++++--------------- 1 file changed, 9 insertions(+), 37 deletions(-) diff --git a/tools/testing/selftests/kvm/aarch64/debug-exceptions.c b/tools/testing/selftests/kvm/aarch64/debug-exceptions.c index 0c237022f4d3..040e4d7f8755 100644 --- a/tools/testing/selftests/kvm/aarch64/debug-exceptions.c +++ b/tools/testing/selftests/kvm/aarch64/debug-exceptions.c @@ -181,23 +181,17 @@ static volatile char write_data; static void guest_code(uint8_t bpn, uint8_t wpn) { - GUEST_SYNC(0); - /* Software-breakpoint */ reset_debug_state(); asm volatile("sw_bp: brk #0"); GUEST_ASSERT_EQ(sw_bp_addr, PC(sw_bp)); - GUEST_SYNC(1); - /* Hardware-breakpoint */ reset_debug_state(); install_hw_bp(bpn, PC(hw_bp)); asm volatile("hw_bp: nop"); GUEST_ASSERT_EQ(hw_bp_addr, PC(hw_bp)); - GUEST_SYNC(2); - /* Hardware-breakpoint + svc */ reset_debug_state(); install_hw_bp(bpn, PC(bp_svc)); @@ -205,8 +199,6 @@ static void guest_code(uint8_t bpn, uint8_t wpn) GUEST_ASSERT_EQ(hw_bp_addr, PC(bp_svc)); GUEST_ASSERT_EQ(svc_addr, PC(bp_svc) + 4); - GUEST_SYNC(3); - /* Hardware-breakpoint + software-breakpoint */ reset_debug_state(); install_hw_bp(bpn, PC(bp_brk)); @@ -214,8 +206,6 @@ static void guest_code(uint8_t bpn, uint8_t wpn) GUEST_ASSERT_EQ(sw_bp_addr, PC(bp_brk)); GUEST_ASSERT_EQ(hw_bp_addr, PC(bp_brk)); - GUEST_SYNC(4); - /* Watchpoint */ reset_debug_state(); install_wp(wpn, PC(write_data)); @@ -223,8 +213,6 @@ static void guest_code(uint8_t bpn, uint8_t wpn) GUEST_ASSERT_EQ(write_data, 'x'); GUEST_ASSERT_EQ(wp_data_addr, PC(write_data)); - GUEST_SYNC(5); - /* Single-step */ reset_debug_state(); install_ss(); @@ -238,8 +226,6 @@ static void guest_code(uint8_t bpn, uint8_t wpn) GUEST_ASSERT_EQ(ss_addr[1], PC(ss_start) + 4); GUEST_ASSERT_EQ(ss_addr[2], PC(ss_start) + 8); - GUEST_SYNC(6); - /* OS Lock does not block software-breakpoint */ reset_debug_state(); enable_os_lock(); @@ -247,8 +233,6 @@ static void guest_code(uint8_t bpn, uint8_t wpn) asm volatile("sw_bp2: brk #0"); GUEST_ASSERT_EQ(sw_bp_addr, PC(sw_bp2)); - GUEST_SYNC(7); - /* OS Lock blocking hardware-breakpoint */ reset_debug_state(); enable_os_lock(); @@ -257,8 +241,6 @@ static void guest_code(uint8_t bpn, uint8_t wpn) asm volatile("hw_bp2: nop"); GUEST_ASSERT_EQ(hw_bp_addr, 0); - GUEST_SYNC(8); - /* OS Lock blocking watchpoint */ reset_debug_state(); enable_os_lock(); @@ -269,8 +251,6 @@ static void guest_code(uint8_t bpn, uint8_t wpn) GUEST_ASSERT_EQ(write_data, 'x'); GUEST_ASSERT_EQ(wp_data_addr, 0); - GUEST_SYNC(9); - /* OS Lock blocking single-step */ reset_debug_state(); enable_os_lock(); @@ -370,7 +350,6 @@ static void test_guest_debug_exceptions(void) struct kvm_vcpu *vcpu; struct kvm_vm *vm; struct ucall uc; - int stage; vm = vm_create_with_one_vcpu(&vcpu, guest_code); ucall_init(vm, NULL); @@ -391,23 +370,16 @@ static void test_guest_debug_exceptions(void) /* Run tests with breakpoint#0 and watchpoint#0. */ vcpu_args_set(vcpu, 2, 0, 0); - for (stage = 0; stage < 11; stage++) { - vcpu_run(vcpu); - switch (get_ucall(vcpu, &uc)) { - case UCALL_SYNC: - TEST_ASSERT(uc.args[1] == stage, - "Stage %d: Unexpected sync ucall, got %lx", - stage, (ulong)uc.args[1]); - break; - case UCALL_ABORT: - REPORT_GUEST_ASSERT_2(uc, "values: %#lx, %#lx"); - break; - case UCALL_DONE: - goto done; - default: - TEST_FAIL("Unknown ucall %lu", uc.cmd); - } + vcpu_run(vcpu); + switch (get_ucall(vcpu, &uc)) { + case UCALL_ABORT: + REPORT_GUEST_ASSERT_2(uc, "values: %#lx, %#lx"); + break; + case UCALL_DONE: + goto done; + default: + TEST_FAIL("Unknown ucall %lu", uc.cmd); } done: From patchwork Thu Oct 20 05:41:59 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Reiji Watanabe X-Patchwork-Id: 13012634 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 B27A3C4332F for ; Thu, 20 Oct 2022 05:45:04 +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=CwFrpKJ3rpDEmTGkM1Z2lOvhYn4/k/jHRkLHL5T4IsU=; b=ikYDOrChiPx2KvPtyE6Nqr6kI6 Sjsv2RY2aMClXZbQijum5PGoaqNmKe6A5TRBx/ifcCUGre3d2dSKiQX3S/+NtXK5ZR75ApHwi5V1X 7+m2KEfvhCzwXPx5PFmRqs+0x6rlK8Oj9qiDZ22yIB5mrp9dyuQFOdL0KAqCKNOxGpjFP63Bvw2ji jT1FjvGaDS9a0WQxz8hNwGNhj5JMt8LSqWu5dAEYs4h7rJWs+OGXIVdsvOkwyT7n+J0VXQOEWMbf0 7jJe55W3h7HHaGhlUe13Jyo+kDp3AA/K9hvFSk0CXhXdJjJ+pPECJwTDjrHqAy8O9ODFcovGeK+H/ 96vPEuxQ==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.94.2 #2 (Red Hat Linux)) id 1olOLT-00AWAS-QY; Thu, 20 Oct 2022 05:43:57 +0000 Received: from mail-yb1-xb4a.google.com ([2607:f8b0:4864:20::b4a]) by bombadil.infradead.org with esmtps (Exim 4.94.2 #2 (Red Hat Linux)) id 1olOL6-00AVTq-7O for linux-arm-kernel@lists.infradead.org; Thu, 20 Oct 2022 05:43:33 +0000 Received: by mail-yb1-xb4a.google.com with SMTP id e8-20020a5b0cc8000000b006bca0fa3ab6so18179767ybr.0 for ; Wed, 19 Oct 2022 22:43:31 -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=VB1jPPUEjrX48I4GSjyuQn7W+BcJBZ1KSoLIzPYJb4c=; b=ZBvzHWXEg5+0LfNox4fGQHvZCGExRABrADPgKQ0uJAT3GS2bcwXVcPUHDokKK0oD8e rBfcnafeNZELKVFMbhHowJDe7++TZWn9+acFfzRzNTYOvkyUYvbGXQueYUS7+V7xHqjc pASv4I9AmarKpMizQUqSSMGE+PrD1DktzRC0sEF4OWpoRrGdgBAo3uvOROA8AlwjqjE0 bxaJb3Vla6LFM5hsDsBAYwGA5biTNljRB4SUgd2nJUMnSSiio4kL7inDOrpqnyBxmh5O 0tPO6YMpMe3QmY5eX0aMQCl+cXZNO+TWL4qwf6QJ270u6kIT3RQormWGvj9KrJgD9jYd Rfmw== 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=VB1jPPUEjrX48I4GSjyuQn7W+BcJBZ1KSoLIzPYJb4c=; b=4D2KhonWni0w2qz7l2+vVHrlw49EncAsDOuvLoMWcxnB/oy2Me26pd03neYTKas/Ia viO9LKRAOGTm/Mj4wPy9NK7IR5DqD5KF06HWkzYPCxcW3pcuEXO3U3vdvTvl0hau862f t71anWRvD9HZsPT3toeZdRgkc45c8ewRgU0KdwYcEUPN548MrjHiWU78VABlkjdlAWYl NKgvOzl7le4alYzwwIAatFe1lCf9Xn47oGGXjZxYWB9Kh5GM3mkwjKU/jJk2ICSowoBg YUml4DiNzUsrGE14JmIVEKkc3jmbekCte5BBgV/oVaf0UEGI9+ndOj4mAr6K1lhpJypb gGbQ== X-Gm-Message-State: ACrzQf0FIsiep6MZNMYZAXlDW4DY1e2srKongKrmZSvIiDwK/qhhOeJn f3R/PH5izigKsZtWSSA0swLTESphQls= X-Google-Smtp-Source: AMsMyM4QU19wSO5ZMBNGHX43y4ZfNhPpdLhf7KWE0/041MMlzko8xOXHq23D3L2kQwLsCPfLQLR/LWK3xuY= X-Received: from reijiw-west4.c.googlers.com ([fda3:e722:ac3:cc00:20:ed76:c0a8:aa1]) (user=reijiw job=sendgmr) by 2002:a25:a4ea:0:b0:6c0:2f38:431d with SMTP id g97-20020a25a4ea000000b006c02f38431dmr10273171ybi.276.1666244610630; Wed, 19 Oct 2022 22:43:30 -0700 (PDT) Date: Wed, 19 Oct 2022 22:41:59 -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-7-reijiw@google.com> Subject: [PATCH v2 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-20221019_224332_295689_A4FFA74E X-CRM114-Status: GOOD ( 11.10 ) 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. No functional change intended. 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 040e4d7f8755..72ec9bb16682 100644 --- a/tools/testing/selftests/kvm/aarch64/debug-exceptions.c +++ b/tools/testing/selftests/kvm/aarch64/debug-exceptions.c @@ -337,11 +337,8 @@ static void guest_code_ss(int test_cnt) GUEST_DONE(); } -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 FIELD_GET(ARM64_FEATURE_MASK(ID_AA64DFR0_DEBUGVER), id_aa64dfr0); } @@ -466,9 +463,11 @@ int main(int argc, char *argv[]) struct kvm_vm *vm; int opt; int ss_iteration = 10000; + uint64_t aa64dfr0; vm = vm_create_with_one_vcpu(&vcpu, guest_code); - __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."); kvm_vm_free(vm); From patchwork Thu Oct 20 05:42:00 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Reiji Watanabe X-Patchwork-Id: 13012635 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 B8E66C433FE for ; Thu, 20 Oct 2022 05:45: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: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=TQeDyrnD5WK0WkUvnkPtP3lENxMXATwg87WhVivJCEM=; b=Qz1ukAqjXXE2JVtK916/VlRJWM Hk31LoDRjU+rwWK2msQ6tQmxH7C0udwVwJhEteK36OKRH3i1f16ZJhs6l8fOJ6HbwF6TWLpLwr2Sl Q7/fPWcGQhMHHcIXdxyhTUBnyO6yQN1kkifcdvgB1WbfUfKefrleMQqKy09RUzvjhm9oIPMGPcmlJ SUxRyyZ6ttr+QEcLP6DQn71R3Q6a7kKGm60/X0ZPdG6Lb9k66CHfr5fSqCax4kQbASvMqrh13Oh59 dQldXd6rPN6wgqQZtGvtstP4opq5ZYHTOq2nVPI90AetdJzEsvdjKNioLdFeQl+fKiFKWjik6P8jT TfIkdUFw==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.94.2 #2 (Red Hat Linux)) id 1olOLm-00AWs9-NV; Thu, 20 Oct 2022 05:44:15 +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 1olOLL-00AV34-P7 for linux-arm-kernel@lists.infradead.org; Thu, 20 Oct 2022 05:43:49 +0000 Received: by mail-yw1-x1149.google.com with SMTP id 00721157ae682-367f94b9b16so17896257b3.11 for ; Wed, 19 Oct 2022 22:43:46 -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=oOYOygB9wgU7oohT9RJUnRPUR0sr23f6giwJ3lgqMuk=; b=pnLO+fv5ly2qcHUWCKLt3EUiUpqInxinUZeyTk5bKFD9rWzz62b8z6Im7diM3LlfrI ZiTbn1vNXiMirnaYW0OzA1SFNkR20MDXyf/IKiO35cUXNeTxdJy9jwmZwuRJQic/aUB1 M07OM3NLcuZD6g+OH2McHlchBGEM8WqdA1dpl0vZNpHi7o2QgkZVwBmI50B0P72D6ect +PSf8Mb/btVDSO01nWPIQUH4pzs6kBIZ2nLkN7Mqtyz+Z5TqVadrdAvyD7uzoJBz//sp tULWZHRDZpdAfg73/neuToQEQ+V8MbkOepFTrWsZGzXKpYwhlSgoHELroHNKkpEjKBWX DBrg== 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=oOYOygB9wgU7oohT9RJUnRPUR0sr23f6giwJ3lgqMuk=; b=kuJmunrcvBElzZca00Txh0JcMyT3ba6NwRnTDqGoaKOIL1iKIAgNvDkZSMeAno9TJM ipkOEZgy37Oflljer9Hbwk0/vXMenDRPD9c02rM1zY9LGPM6Pu/nVzCtMCttkNVJVWNI 38Sn7QbO1y0RW75+ovqyMsZ/AoeRKPqHaXcClbjnszNX5gqvw8FM/jO5mH0RldnNFJfS pglfBckINt6gJEkzFg19GnnZgvw1Nx/6RtwyZWnFm9m1r8f+Lrd0KfvtfNbZ2gFtMtVO guofi311cQbdmRPDM85f9o4BXo8k8DFxmBRN1Avv6gq2KmEcX1oxa0ARhGiTrm43qT7+ X/JQ== X-Gm-Message-State: ACrzQf0nkZxNdLJnLT+6IkkDZYrCPBhYbpt40UHixnoasp7nKJ6TK284 ugKe3sl3rqG4PJSbFyUYAjCjNERUKIY= X-Google-Smtp-Source: AMsMyM6kx5OcEqJmzB/hkt4jneBqv+i1c8NLkTNAN23PWELR4sidAYtN4LhOl1nWljVBf7oA5kCb/r5iJNQ= X-Received: from reijiw-west4.c.googlers.com ([fda3:e722:ac3:cc00:20:ed76:c0a8:aa1]) (user=reijiw job=sendgmr) by 2002:a25:5f52:0:b0:6c1:8af:5208 with SMTP id h18-20020a255f52000000b006c108af5208mr9557699ybm.220.1666244626721; Wed, 19 Oct 2022 22:43:46 -0700 (PDT) Date: Wed, 19 Oct 2022 22:42:00 -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-8-reijiw@google.com> Subject: [PATCH v2 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-20221019_224347_858448_25295F1C X-CRM114-Status: GOOD ( 16.71 ) 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. The new test case uses a pair of breakpoints. One is the higiest numbered context-aware breakpoint (for Context ID match), and the other one is the breakpoint#0 (for Address Match), which is linked to the context-aware breakpoint. Signed-off-by: Reiji Watanabe --- .../selftests/kvm/aarch64/debug-exceptions.c | 63 +++++++++++++++++-- 1 file changed, 57 insertions(+), 6 deletions(-) diff --git a/tools/testing/selftests/kvm/aarch64/debug-exceptions.c b/tools/testing/selftests/kvm/aarch64/debug-exceptions.c index 72ec9bb16682..362e7668a978 100644 --- a/tools/testing/selftests/kvm/aarch64/debug-exceptions.c +++ b/tools/testing/selftests/kvm/aarch64/debug-exceptions.c @@ -12,6 +12,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) @@ -22,7 +26,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; extern unsigned char iter_ss_begin, iter_ss_end; static volatile uint64_t sw_bp_addr, hw_bp_addr; static volatile uint64_t wp_addr, wp_data_addr; @@ -105,6 +109,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); @@ -166,6 +171,31 @@ static void install_hw_bp(uint8_t bpn, uint64_t addr) enable_monitor_debug_exceptions(); } +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 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 normal breakpoint for Linked Address Match, and link it + * 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_monitor_debug_exceptions(); +} + static void install_ss(void) { uint32_t mdscr; @@ -179,8 +209,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 = 0xabcdef; /* a random context number */ + /* Software-breakpoint */ reset_debug_state(); asm volatile("sw_bp: brk #0"); @@ -263,6 +295,17 @@ 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_DONE(); } @@ -342,11 +385,12 @@ static int debug_version(uint64_t id_aa64dfr0) return FIELD_GET(ARM64_FEATURE_MASK(ID_AA64DFR0_DEBUGVER), id_aa64dfr0); } -static void test_guest_debug_exceptions(void) +static void test_guest_debug_exceptions(uint64_t aa64dfr0) { struct kvm_vcpu *vcpu; struct kvm_vm *vm; struct ucall uc; + uint8_t brp_num; vm = vm_create_with_one_vcpu(&vcpu, guest_code); ucall_init(vm, NULL); @@ -365,8 +409,15 @@ static void test_guest_debug_exceptions(void) 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 */ + brp_num = FIELD_GET(ARM64_FEATURE_MASK(ID_AA64DFR0_BRPS), aa64dfr0) + 1; + __TEST_REQUIRE(brp_num >= 2, "At least two breakpoints are required"); + + /* + * Run tests with breakpoint#0, watchpoint#0, and the higiest + * numbered (context-aware) breakpoint. + */ + vcpu_args_set(vcpu, 3, 0, 0, brp_num - 1); vcpu_run(vcpu); switch (get_ucall(vcpu, &uc)) { @@ -483,7 +534,7 @@ int main(int argc, char *argv[]) } } - test_guest_debug_exceptions(); + test_guest_debug_exceptions(aa64dfr0); test_single_step_from_userspace(ss_iteration); return 0; 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(); } From patchwork Thu Oct 20 05:42:02 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Reiji Watanabe X-Patchwork-Id: 13012637 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 54FE5C433FE for ; Thu, 20 Oct 2022 05:45:55 +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=77bKdzUVfMCP4qkEMXUl600CRJ1Xhsyw+xux/6V2NTU=; b=sWmbxIr4ZE5KZ/OKIK+dMPqDPt bq0MGb4Khm3m8NqKX3lN9dQFWCx3xhXKnCj9GFsetZr7WxqOiMuLdvnhxCgJkqwJerSQw+/i5e4ek gsIrBuSlxRE6c4l9IY43dCuHmLgJnVkGfuHeh1LA2rQRLKfoRXh0bcUmu9lC2dG7Ddw2bQtvHld7M 3rp31R1BKAjMQlOfr0BqsoLC8QRaw7CMQQQ+lipgZ1XI/sUfNY042JVmDG6jpQ35sGtjfm9SMYK6l YAqxCdcnS6FrmxicTHWhfKYOHp4Fj+qWLCMNxNb+XY+BJAdZ3Ag8yFAotOyMRz9AYatneR2TU2/Vs B5yEW7vg==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.94.2 #2 (Red Hat Linux)) id 1olOMM-00AXbz-So; Thu, 20 Oct 2022 05:44:51 +0000 Received: from mail-pf1-x449.google.com ([2607:f8b0:4864:20::449]) by bombadil.infradead.org with esmtps (Exim 4.94.2 #2 (Red Hat Linux)) id 1olOLQ-00AW6f-0i for linux-arm-kernel@lists.infradead.org; Thu, 20 Oct 2022 05:43:53 +0000 Received: by mail-pf1-x449.google.com with SMTP id q18-20020aa79832000000b00562d921e30aso10554047pfl.4 for ; Wed, 19 Oct 2022 22:43:50 -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=B5VialaYDd/5nDZq2FGZQSkkeS3yDmkJ8xITb2jtJu4=; b=JCQN7ZN/2N0cWyp8F8z9Q/AWQsvHJudQPiteYqEIcj7XfWugeQhVkTmnP0ARsWsoks ucgnIuxwkVOi6HfufXCOivOoWc0OAfMaQ5LcZ7LoJDphUF5BD661KNYr13g9b8M69Wg5 sYWriD3ommK1rvL7wYoQei3CW09bn2tk9bumU08bD2tbJvn7h2d3n2uBe3lkScwHMXo/ +pgtGuA2YWI5nKvdUoxnT816Q+TSg6g4SRqRLOa1HBJbbymWGCLYzRrE86VGWUgxGIhh fAoVU8gmlDs5BJ+XuOZSg+xtcNGDwIO9ya/KVTRPWvkUMcFeE/PKg4uoGNBwomtfA+sz SrMg== 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=B5VialaYDd/5nDZq2FGZQSkkeS3yDmkJ8xITb2jtJu4=; b=St/CEkWhXQ/B7pEPzzodjVA8ma1WH7XkBkWN949REfVD9vnoG7rk2BHC4i/O4SZRXO oXlTGwdnhz+vPRrnIVVo1TlHmmYRJuV6VQ/Kv0CrIGDToC06LSpsyp/wGL4RV8fmhp3d 8OgM1GaGyk+MzNGl0jQp8wbivnKhfonlqxNotNGVyalK7vWBZJ5oqKmtEQNnHWkE57mA MU3MWS1JAmVix6MX24I4k+QUzImci71pLe0HL45tHwPs7817CZlX2wRC0Mo4KDdNeTar l3D51wJhjpE/EJWSJ84pb5HTKv8ZzUky+Pnp/YWgEzJcW8IaVUq0AaZU9QkNEk/zaFYw xHDQ== X-Gm-Message-State: ACrzQf2cdCMq/XZtbEVYLEYicIGz6Bhzn6jsOkRzX32HkwhkVSZy2OFd Eo2seoqnUaHtiEadVNETxIWk+u3nLmc= X-Google-Smtp-Source: AMsMyM4nwPtJ6JpQSfu86pZslSfGKYI7Hejk4DKn49pB5qd4AvXEqW2ZJclxhcgitaqs9lCMA2XixsTUavc= X-Received: from reijiw-west4.c.googlers.com ([fda3:e722:ac3:cc00:20:ed76:c0a8:aa1]) (user=reijiw job=sendgmr) by 2002:a17:90a:b794:b0:20a:eab5:cf39 with SMTP id m20-20020a17090ab79400b0020aeab5cf39mr2379113pjr.1.1666244629981; Wed, 19 Oct 2022 22:43:49 -0700 (PDT) Date: Wed, 19 Oct 2022 22:42:02 -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-10-reijiw@google.com> Subject: [PATCH v2 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-20221019_224352_130985_A36C291F X-CRM114-Status: GOOD ( 15.46 ) 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 | 54 ++++++++++++++----- 1 file changed, 42 insertions(+), 12 deletions(-) diff --git a/tools/testing/selftests/kvm/aarch64/debug-exceptions.c b/tools/testing/selftests/kvm/aarch64/debug-exceptions.c index 73a95e6b345e..b30add3e7726 100644 --- a/tools/testing/selftests/kvm/aarch64/debug-exceptions.c +++ b/tools/testing/selftests/kvm/aarch64/debug-exceptions.c @@ -420,12 +420,11 @@ static int debug_version(uint64_t id_aa64dfr0) return FIELD_GET(ARM64_FEATURE_MASK(ID_AA64DFR0_DEBUGVER), id_aa64dfr0); } -static void test_guest_debug_exceptions(uint64_t aa64dfr0) +static void test_guest_debug_exceptions(uint8_t bpn, uint8_t wpn, uint8_t ctx_bpn) { struct kvm_vcpu *vcpu; struct kvm_vm *vm; struct ucall uc; - uint8_t brp_num; vm = vm_create_with_one_vcpu(&vcpu, guest_code); ucall_init(vm, NULL); @@ -444,15 +443,9 @@ static void test_guest_debug_exceptions(uint64_t aa64dfr0) vm_install_sync_handler(vm, VECTOR_SYNC_CURRENT, ESR_EC_SVC64, guest_svc_handler); - /* Number of breakpoints */ - brp_num = FIELD_GET(ARM64_FEATURE_MASK(ID_AA64DFR0_BRPS), aa64dfr0) + 1; - __TEST_REQUIRE(brp_num >= 2, "At least two breakpoints are required"); - - /* - * Run tests with breakpoint#0, watchpoint#0, and the higiest - * numbered (context-aware) breakpoint. - */ - vcpu_args_set(vcpu, 3, 0, 0, brp_num - 1); + /* 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); vcpu_run(vcpu); switch (get_ucall(vcpu, &uc)) { @@ -535,6 +528,43 @@ void test_single_step_from_userspace(int test_cnt) 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_guest_debug_exceptions_all(uint64_t aa64dfr0) +{ + uint8_t brp_num, wrp_num, ctx_brp_num, normal_brp_num, ctx_brp_base; + int b, w, c; + + /* Number of breakpoints */ + brp_num = FIELD_GET(ARM64_FEATURE_MASK(ID_AA64DFR0_BRPS), aa64dfr0) + 1; + __TEST_REQUIRE(brp_num >= 2, "At least two breakpoints are required"); + + /* Number of watchpoints */ + wrp_num = FIELD_GET(ARM64_FEATURE_MASK(ID_AA64DFR0_WRPS), aa64dfr0) + 1; + + /* Number of context aware breakpoints */ + ctx_brp_num = FIELD_GET(ARM64_FEATURE_MASK(ID_AA64DFR0_CTX_CMPS), aa64dfr0) + 1; + + pr_debug("%s brp_num:%d, wrp_num:%d, ctx_brp_num:%d\n", __func__, + brp_num, wrp_num, ctx_brp_num); + + /* Number of normal (non-context aware) breakpoints */ + normal_brp_num = brp_num - ctx_brp_num; + + /* 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++) + test_guest_debug_exceptions(b, w, c); + } + } +} + static void help(char *name) { puts(""); @@ -569,7 +599,7 @@ int main(int argc, char *argv[]) } } - test_guest_debug_exceptions(aa64dfr0); + test_guest_debug_exceptions_all(aa64dfr0); test_single_step_from_userspace(ss_iteration); return 0;