From patchwork Tue Apr 19 06:55:44 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Reiji Watanabe X-Patchwork-Id: 12817554 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 CA623C433EF for ; Tue, 19 Apr 2022 07:27:37 +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=jck1COKNePTW0wvp7/43/UYBI6zqTp+ZKb18zdQKAEc=; b=IBN/eYbDEhIgzqszfLcKDkbihL XZKpFOFccB05m9OCE31wE7JvUYl2cTwbPd9XNoFYZ2+Kbn8p5/mSzPPhPskmN3f78U/fIR8BcUYAo URFc9LPJY402s1y5zXefUtVsNPJvunG4pMRjKwi1rwHA3rFmIq8/ZY0zsBgE9sjV7NNgGaOt/RV4r XTNsBfRV5NOgtdp3PtPvztHXhRSUw15HcOyKqE5UgdfFgWShhNd8eENEnNHT0fbmw2fHUzP1zoWSZ GafTOh3AggpaQfdiROtm4MCss4RtaB2t+KW5GkUxuQAafUWMwfgdn0fNaX/zFK7u3NZm9ntQ0O+Jr k0XdV7cQ==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.94.2 #2 (Red Hat Linux)) id 1ngiFd-001yTm-0k; Tue, 19 Apr 2022 07:26:18 +0000 Received: from mail-pl1-x649.google.com ([2607:f8b0:4864:20::649]) by bombadil.infradead.org with esmtps (Exim 4.94.2 #2 (Red Hat Linux)) id 1nghoP-001nqs-1G for linux-arm-kernel@lists.infradead.org; Tue, 19 Apr 2022 06:58:13 +0000 Received: by mail-pl1-x649.google.com with SMTP id i10-20020a1709026aca00b00158f14b4f2fso3812807plt.2 for ; Mon, 18 Apr 2022 23:58:08 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20210112; h=date:in-reply-to:message-id:mime-version:references:subject:from:to :cc; bh=mjj9/ZURjjtGQaz2LLl2krlBnNho3fyEfvR2R+fnkyk=; b=Cx/niwv6W7Y06XURKByUCxiOI2JS42u8ZRsB4Jd/xNk9tuJcTxkf6DGO2ozYf4I2US ZU5gnlaHf3BOrOeCv/etuwgapIvL2bqk3oDXaueadh0neyRo+SRUNGL8votl7vplAKIM sHEcbNzdEG1JDsorZDIsYKh0benCQF67aJbA83qbMyT0rAqvaaie74ccZbn2UKz7aKPj rdih6zJ2hBj5+wcu/NsMPytHpAWF1ZDLiIr+vMhcou+4/o0JwtMNZ0uLdoKh4FJr+/Aw 2l9wU0ZAeDtDkWgA6X6SW5F7yr+BUmvcruGK7QcRMj4E99qkjqwTBZGm703z1PFKPYWV fU1Q== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:date:in-reply-to:message-id:mime-version :references:subject:from:to:cc; bh=mjj9/ZURjjtGQaz2LLl2krlBnNho3fyEfvR2R+fnkyk=; b=3bownD854rG6z+K4Lc0I+1loMEVhJ5VYCJyrARdI2zwbdqsmE5MFqQ/4L0zi8MYoHl cEaHX2FC3N8nHr/FfWQP6LBZD6slngv6T5EO5NOYhzOXn8xyfZVEuDNbzW/Nq1LemUOy 35Q9STg8tAgCWhoQq8ArXX5kaMYjKfhSf60YrCXd7O/Rn+2oPQedNagm8rdrzr0B+UCt UF2fANmtyUgWGV/ce5WA8ph6iRPvp3U9Ls9pqU9z2hdyjz6qyzXvjEiedsMsp4i5gxKV lE8GmP7/AfUtHV8eITt9deWTZZqiDfDENlxyT6ytvUSJDETr11w1gH/NxY5kYmowVoI5 W8pg== X-Gm-Message-State: AOAM533kula4OowhfpPMv7NboMnYmJvMpl/Gpyfm14DyAXf9lquqL+qM 7MzQrK6hXsZDS4y57i9gk6SXA6EEF2k= X-Google-Smtp-Source: ABdhPJxetHGB4V+UPVW7WLQKsn2PTcz1+SOcEmT+cqxyd2F8wg7N+PKJyvCJRL8FQa0pqjwk4Zbwsa8b0eQ= X-Received: from reiji-vws-sp.c.googlers.com ([fda3:e722:ac3:cc00:7f:e700:c0a8:3d59]) (user=reijiw job=sendgmr) by 2002:a17:90b:2384:b0:1cb:5223:9dc4 with SMTP id mr4-20020a17090b238400b001cb52239dc4mr276931pjb.1.1650351487187; Mon, 18 Apr 2022 23:58:07 -0700 (PDT) Date: Mon, 18 Apr 2022 23:55:44 -0700 In-Reply-To: <20220419065544.3616948-1-reijiw@google.com> Message-Id: <20220419065544.3616948-39-reijiw@google.com> Mime-Version: 1.0 References: <20220419065544.3616948-1-reijiw@google.com> X-Mailer: git-send-email 2.36.0.rc0.470.gd361397f0d-goog Subject: [PATCH v7 38/38] KVM: arm64: selftests: Test breakpoint/watchpoint changing 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 , Will Deacon , Andrew Jones , Fuad Tabba , Peng Liang , Peter Shier , 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-20220418_235809_163865_BB6C7CB8 X-CRM114-Status: GOOD ( 14.30 ) 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 test cases that uses every breakpoint/watchpoint with various combination of ID_AA64DFR0_EL1.BRPs, WRPs, and CTX_CMPs configuration to the debug-exceptions test. Signed-off-by: Reiji Watanabe --- .../selftests/kvm/aarch64/debug-exceptions.c | 52 ++++++++++++++++--- 1 file changed, 46 insertions(+), 6 deletions(-) diff --git a/tools/testing/selftests/kvm/aarch64/debug-exceptions.c b/tools/testing/selftests/kvm/aarch64/debug-exceptions.c index 829fad6c7d58..d8ebbb7985da 100644 --- a/tools/testing/selftests/kvm/aarch64/debug-exceptions.c +++ b/tools/testing/selftests/kvm/aarch64/debug-exceptions.c @@ -701,18 +701,19 @@ static void check_debug_regs(struct kvm_vm *vm, uint32_t vcpu, } } -void run_test(uint8_t bpn, uint8_t wpn, uint8_t ctx_bpn) +void run_test(uint64_t aa64dfr0, uint8_t bpn, uint8_t wpn, uint8_t ctx_bpn) { struct kvm_vm *vm; struct ucall uc; int stage; - uint64_t aa64dfr0; uint8_t nbps, nwps; bool debug_reg_test = false; - pr_debug("%s bpn:%d, wpn:%d, ctx_bpn:%d\n", __func__, bpn, wpn, ctx_bpn); - + pr_debug("%s aa64dfr0:0x%lx, bpn:%d, wpn:%d, ctx_bpn:%d\n", __func__, + aa64dfr0, bpn, wpn, ctx_bpn); vm = vm_create_default(VCPU_ID, 0, guest_code); + set_reg(vm, VCPU_ID, KVM_ARM64_SYS_REG(SYS_ID_AA64DFR0_EL1), aa64dfr0); + ucall_init(vm, NULL); vm_init_descriptor_tables(vm); @@ -810,15 +811,33 @@ void test_debug(uint64_t aa64dfr0) 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++) - run_test(b, w, c); + run_test(aa64dfr0, b, w, c); } } } +uint64_t update_aa64dfr0_bwrp(uint64_t dfr0, uint8_t brps, uint8_t wrps, + uint8_t ctx_brps) +{ + /* Clear brps/wrps/ctx_cmps fields */ + dfr0 &= ~(ARM64_FEATURE_MASK(ID_AA64DFR0_BRPS) | + ARM64_FEATURE_MASK(ID_AA64DFR0_WRPS) | + ARM64_FEATURE_MASK(ID_AA64DFR0_CTX_CMPS)); + + /* Set new brps/wrps/ctx_cmps fields */ + dfr0 |= ((uint64_t)brps << ID_AA64DFR0_BRPS_SHIFT) | + ((uint64_t)wrps << ID_AA64DFR0_WRPS_SHIFT) | + ((uint64_t)ctx_brps << ID_AA64DFR0_CTX_CMPS_SHIFT); + + return dfr0; +} + int main(int argc, char *argv[]) { struct kvm_vm *vm; - uint64_t aa64dfr0; + uint64_t aa64dfr0, test_aa64dfr0; + uint8_t max_brps, max_wrps, max_ctx_brps; + int bs, ws, cs; vm = vm_create_default(VCPU_ID, 0, guest_code); get_reg(vm, VCPU_ID, KVM_ARM64_SYS_REG(SYS_ID_AA64DFR0_EL1), &aa64dfr0); @@ -831,5 +850,26 @@ int main(int argc, char *argv[]) /* Run debug tests with the default configuration */ test_debug(aa64dfr0); + + if (!kvm_check_cap(KVM_CAP_ARM_ID_REG_CONFIGURABLE)) + return 0; + + /* + * Run debug tests with various number of breakpoints/watchpoints + * configuration. + */ + max_brps = cpuid_extract_uftr(aa64dfr0, ID_AA64DFR0_BRPS_SHIFT); + max_wrps = cpuid_extract_uftr(aa64dfr0, ID_AA64DFR0_WRPS_SHIFT); + max_ctx_brps = cpuid_extract_uftr(aa64dfr0, ID_AA64DFR0_CTX_CMPS_SHIFT); + for (cs = 0; cs <= max_ctx_brps; cs++) { + for (bs = cs + 1; bs <= max_brps; bs++) { + for (ws = 1; ws <= max_wrps; ws++) { + test_aa64dfr0 = update_aa64dfr0_bwrp(aa64dfr0, + bs, ws, cs); + test_debug(test_aa64dfr0); + } + } + } + return 0; }