From patchwork Sat Apr 4 14:36:53 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Andrew Jones X-Patchwork-Id: 11474321 Return-Path: Received: from mail.kernel.org (pdx-korg-mail-1.web.codeaurora.org [172.30.200.123]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 0147615AB for ; Sat, 4 Apr 2020 14:38:12 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id D490E20731 for ; Sat, 4 Apr 2020 14:38:11 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (1024-bit key) header.d=redhat.com header.i=@redhat.com header.b="axxVR5v+" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726353AbgDDOh5 (ORCPT ); Sat, 4 Apr 2020 10:37:57 -0400 Received: from us-smtp-delivery-1.mimecast.com ([207.211.31.120]:34679 "EHLO us-smtp-1.mimecast.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S1726248AbgDDOh4 (ORCPT ); Sat, 4 Apr 2020 10:37:56 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1586011076; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=4TH7o6uPii+FVWXIRQDwrHwi8uTL0Zd9SNThpzh1Yhs=; b=axxVR5v+RL5nxtCS+ru3FnMTEtQpustGR9fQVFKCglWZqyLQQJTcaxAsqgwqjA4fsWgBB2 y+9J6UxaJ24KDMMa7BlZQqptjJsr3Y6xPG/OAUMhxhehpEp2e8bUaw66eXWC8+dccjoVdW NmLSD/l6TAgWVeA5/xopP4Qyk/CTXyY= Received: from mimecast-mx01.redhat.com (mimecast-mx01.redhat.com [209.132.183.4]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-321-jqwY0IBlPfCljN1pw65vkw-1; Sat, 04 Apr 2020 10:37:53 -0400 X-MC-Unique: jqwY0IBlPfCljN1pw65vkw-1 Received: from smtp.corp.redhat.com (int-mx01.intmail.prod.int.phx2.redhat.com [10.5.11.11]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id 7CD5B107B113; Sat, 4 Apr 2020 14:37:41 +0000 (UTC) Received: from kamzik.brq.redhat.com (unknown [10.40.192.30]) by smtp.corp.redhat.com (Postfix) with ESMTP id 42CBA9B912; Sat, 4 Apr 2020 14:37:35 +0000 (UTC) From: Andrew Jones To: pbonzini@redhat.com Cc: kvm@vger.kernel.org, kvmarm@lists.cs.columbia.edu, Alexandru Elisei , Drew Jones , Laurent Vivier , Thomas Huth , David Hildenbrand , Janosch Frank Subject: [PULL kvm-unit-tests 01/39] Makefile: Use no-stack-protector compiler options Date: Sat, 4 Apr 2020 16:36:53 +0200 Message-Id: <20200404143731.208138-2-drjones@redhat.com> In-Reply-To: <20200404143731.208138-1-drjones@redhat.com> References: <20200404143731.208138-1-drjones@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.11 Sender: kvm-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: kvm@vger.kernel.org From: Alexandru Elisei Let's fix the typos so that the -fno-stack-protector and -fno-stack-protector-all compiler options are actually used. Tested by compiling for arm64, x86_64 and ppc64 little endian. Before the patch, the arguments were missing from the gcc invocation; after the patch, they were present. Also fixes a compilation error that I was seeing with aarch64 gcc version 9.2.0, where the linker was complaining about an undefined reference to the symbol __stack_chk_guard. Fixes: e5c73790f5f0 ("build: don't reevaluate cc-option shell command") CC: Paolo Bonzini CC: Drew Jones CC: Laurent Vivier CC: Thomas Huth CC: David Hildenbrand CC: Janosch Frank Signed-off-by: Alexandru Elisei Reviewed-by: Thomas Huth Reviewed-by: Laurent Vivier Signed-off-by: Andrew Jones --- Makefile | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/Makefile b/Makefile index 767b6c6a51d0..754ed65ecd2f 100644 --- a/Makefile +++ b/Makefile @@ -55,8 +55,8 @@ COMMON_CFLAGS += -Wignored-qualifiers -Werror frame-pointer-flag=-f$(if $(KEEP_FRAME_POINTER),no-,)omit-frame-pointer fomit_frame_pointer := $(call cc-option, $(frame-pointer-flag), "") -fnostack_protector := $(call cc-option, -fno-stack-protector, "") -fnostack_protector_all := $(call cc-option, -fno-stack-protector-all, "") +fno_stack_protector := $(call cc-option, -fno-stack-protector, "") +fno_stack_protector_all := $(call cc-option, -fno-stack-protector-all, "") wno_frame_address := $(call cc-option, -Wno-frame-address, "") fno_pic := $(call cc-option, -fno-pic, "") no_pie := $(call cc-option, -no-pie, "") From patchwork Sat Apr 4 14:36:54 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Andrew Jones X-Patchwork-Id: 11474305 Return-Path: Received: from mail.kernel.org (pdx-korg-mail-1.web.codeaurora.org [172.30.200.123]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id F403E912 for ; Sat, 4 Apr 2020 14:37:59 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id D1BEC2071C for ; Sat, 4 Apr 2020 14:37:59 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (1024-bit key) header.d=redhat.com header.i=@redhat.com header.b="bZ0NsDvo" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726393AbgDDOh7 (ORCPT ); Sat, 4 Apr 2020 10:37:59 -0400 Received: from us-smtp-delivery-1.mimecast.com ([205.139.110.120]:58688 "EHLO us-smtp-1.mimecast.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S1726230AbgDDOh6 (ORCPT ); Sat, 4 Apr 2020 10:37:58 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1586011077; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=f5/6iYn1/X1EBmc0Lpb8aoWuiKLfFR+TAtLkxR7iQvU=; b=bZ0NsDvoyqGTYTUl/oppTRQ2PWqG0Qyt52gzFImh4oSRd9jxnPsZE6t8p9FWdiqB0E5/i2 99SKxfAvEWKdvzq5ro140zvtIyFbJQfpiID3TxZMPG5n0u0HcVhN0UGyfCWsgX+drIoO0B H9yYgA8bF9Yaj6Mtd17NTLZofTAP3GA= Received: from mimecast-mx01.redhat.com (mimecast-mx01.redhat.com [209.132.183.4]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-486-X8W0NQ34MnSb3nantdKhTg-1; Sat, 04 Apr 2020 10:37:53 -0400 X-MC-Unique: X8W0NQ34MnSb3nantdKhTg-1 Received: from smtp.corp.redhat.com (int-mx01.intmail.prod.int.phx2.redhat.com [10.5.11.11]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id 0FC01140B; Sat, 4 Apr 2020 14:37:44 +0000 (UTC) Received: from kamzik.brq.redhat.com (unknown [10.40.192.30]) by smtp.corp.redhat.com (Postfix) with ESMTP id F1CF29B912; Sat, 4 Apr 2020 14:37:41 +0000 (UTC) From: Andrew Jones To: pbonzini@redhat.com Cc: kvm@vger.kernel.org, kvmarm@lists.cs.columbia.edu, Alexandru Elisei Subject: [PULL kvm-unit-tests 02/39] arm/arm64: psci: Don't run C code without stack or vectors Date: Sat, 4 Apr 2020 16:36:54 +0200 Message-Id: <20200404143731.208138-3-drjones@redhat.com> In-Reply-To: <20200404143731.208138-1-drjones@redhat.com> References: <20200404143731.208138-1-drjones@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.11 Sender: kvm-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: kvm@vger.kernel.org From: Alexandru Elisei The psci test performs a series of CPU_ON/CPU_OFF cycles for CPU 1. This is done by setting the entry point for the CPU_ON call to the physical address of the C function cpu_psci_cpu_die. The compiler is well within its rights to use the stack when generating code for cpu_psci_cpu_die. However, because no stack initialization has been done, the stack pointer is zero, as set by KVM when creating the VCPU. This causes a data abort without a change in exception level. The VBAR_EL1 register is also zero (the KVM reset value for VBAR_EL1), the MMU is off, and we end up trying to fetch instructions from address 0x200. At this point, a stage 2 instruction abort is generated which is taken to KVM. KVM interprets this as an instruction fetch from an I/O region, and injects a prefetch abort into the guest. Prefetch abort is a synchronous exception, and on guest return the VCPU PC will be set to VBAR_EL1 + 0x200, which is... 0x200. The VCPU ends up in an infinite loop causing a prefetch abort while fetching the instruction to service the said abort. To avoid all of this, lets use the assembly function halt as the CPU_ON entry address. Also, expand the check to test that we only get PSCI_RET_SUCCESS exactly once, as we're never offlining the CPU during the test. Signed-off-by: Alexandru Elisei Signed-off-by: Andrew Jones --- arm/psci.c | 14 +++++++++++--- 1 file changed, 11 insertions(+), 3 deletions(-) diff --git a/arm/psci.c b/arm/psci.c index 5c1accb6cea4..ffc09a2e9858 100644 --- a/arm/psci.c +++ b/arm/psci.c @@ -79,13 +79,14 @@ static void cpu_on_secondary_entry(void) cpumask_set_cpu(cpu, &cpu_on_ready); while (!cpu_on_start) cpu_relax(); - cpu_on_ret[cpu] = psci_cpu_on(cpus[1], __pa(cpu_psci_cpu_die)); + cpu_on_ret[cpu] = psci_cpu_on(cpus[1], __pa(halt)); cpumask_set_cpu(cpu, &cpu_on_done); } static bool psci_cpu_on_test(void) { bool failed = false; + int ret_success = 0; int cpu; cpumask_set_cpu(1, &cpu_on_ready); @@ -104,7 +105,7 @@ static bool psci_cpu_on_test(void) cpu_on_start = 1; smp_mb(); - cpu_on_ret[0] = psci_cpu_on(cpus[1], __pa(cpu_psci_cpu_die)); + cpu_on_ret[0] = psci_cpu_on(cpus[1], __pa(halt)); cpumask_set_cpu(0, &cpu_on_done); while (!cpumask_full(&cpu_on_done)) @@ -113,12 +114,19 @@ static bool psci_cpu_on_test(void) for_each_present_cpu(cpu) { if (cpu == 1) continue; - if (cpu_on_ret[cpu] != PSCI_RET_SUCCESS && cpu_on_ret[cpu] != PSCI_RET_ALREADY_ON) { + if (cpu_on_ret[cpu] == PSCI_RET_SUCCESS) { + ret_success++; + } else if (cpu_on_ret[cpu] != PSCI_RET_ALREADY_ON) { report_info("unexpected cpu_on return value: caller=CPU%d, ret=%d", cpu, cpu_on_ret[cpu]); failed = true; } } + if (ret_success != 1) { + report_info("got %d CPU_ON success", ret_success); + failed = true; + } + return !failed; } From patchwork Sat Apr 4 14:36:55 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Andrew Jones X-Patchwork-Id: 11474301 Return-Path: Received: from mail.kernel.org (pdx-korg-mail-1.web.codeaurora.org [172.30.200.123]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 0D98E912 for ; Sat, 4 Apr 2020 14:37:58 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id E00FF2071C for ; Sat, 4 Apr 2020 14:37:57 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (1024-bit key) header.d=redhat.com header.i=@redhat.com header.b="EH/9ue7R" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726371AbgDDOh5 (ORCPT ); Sat, 4 Apr 2020 10:37:57 -0400 Received: from us-smtp-delivery-1.mimecast.com ([205.139.110.120]:53465 "EHLO us-smtp-1.mimecast.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S1726230AbgDDOh4 (ORCPT ); Sat, 4 Apr 2020 10:37:56 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1586011075; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=u+W8aLqjWNoS2hm7NQW8E99+QZ2PFnvwa+mg/8to+p4=; b=EH/9ue7RAfzZcL1HVqD38VAaqqx/Wkm7oSANADA8ErfoHctUeguRilwf3bWonQLQ4YMEhg Nc+elNWhymlAyqODginYqZ0MCy1C8wtYBuRqEKuIyNW/KWN43+ZQCyTUXd+ZRo8mj5xiaC OL+nLlleexgmboZZVfogQHTDoKTAvkQ= Received: from mimecast-mx01.redhat.com (mimecast-mx01.redhat.com [209.132.183.4]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-338-wdevQmdpNLKDzTmd4c2rTA-1; Sat, 04 Apr 2020 10:37:53 -0400 X-MC-Unique: wdevQmdpNLKDzTmd4c2rTA-1 Received: from smtp.corp.redhat.com (int-mx01.intmail.prod.int.phx2.redhat.com [10.5.11.11]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id 8330518AB2DA; Sat, 4 Apr 2020 14:37:46 +0000 (UTC) Received: from kamzik.brq.redhat.com (unknown [10.40.192.30]) by smtp.corp.redhat.com (Postfix) with ESMTP id 8B0089B912; Sat, 4 Apr 2020 14:37:44 +0000 (UTC) From: Andrew Jones To: pbonzini@redhat.com Cc: kvm@vger.kernel.org, kvmarm@lists.cs.columbia.edu, Alexandru Elisei Subject: [PULL kvm-unit-tests 03/39] arm64: timer: Add ISB after register writes Date: Sat, 4 Apr 2020 16:36:55 +0200 Message-Id: <20200404143731.208138-4-drjones@redhat.com> In-Reply-To: <20200404143731.208138-1-drjones@redhat.com> References: <20200404143731.208138-1-drjones@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.11 Sender: kvm-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: kvm@vger.kernel.org From: Alexandru Elisei From ARM DDI 0487E.a glossary, the section "Context synchronization event": "All direct and indirect writes to System registers that are made before the Context synchronization event affect any instruction, including a direct read, that appears in program order after the instruction causing the Context synchronization event." The ISB instruction is a context synchronization event [1]. Add an ISB after all register writes, to make sure that the writes have been completed when we try to test their effects. [1] ARM DDI 0487E.a, section C6.2.96 Signed-off-by: Alexandru Elisei Signed-off-by: Andrew Jones --- arm/timer.c | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/arm/timer.c b/arm/timer.c index f390e8e65d31..c6ea108cfa4b 100644 --- a/arm/timer.c +++ b/arm/timer.c @@ -41,6 +41,7 @@ static u64 read_vtimer_cval(void) static void write_vtimer_cval(u64 val) { write_sysreg(val, cntv_cval_el0); + isb(); } static s32 read_vtimer_tval(void) @@ -51,6 +52,7 @@ static s32 read_vtimer_tval(void) static void write_vtimer_tval(s32 val) { write_sysreg(val, cntv_tval_el0); + isb(); } static u64 read_vtimer_ctl(void) @@ -61,6 +63,7 @@ static u64 read_vtimer_ctl(void) static void write_vtimer_ctl(u64 val) { write_sysreg(val, cntv_ctl_el0); + isb(); } static u64 read_ptimer_counter(void) @@ -76,6 +79,7 @@ static u64 read_ptimer_cval(void) static void write_ptimer_cval(u64 val) { write_sysreg(val, cntp_cval_el0); + isb(); } static s32 read_ptimer_tval(void) @@ -86,6 +90,7 @@ static s32 read_ptimer_tval(void) static void write_ptimer_tval(s32 val) { write_sysreg(val, cntp_tval_el0); + isb(); } static u64 read_ptimer_ctl(void) @@ -96,6 +101,7 @@ static u64 read_ptimer_ctl(void) static void write_ptimer_ctl(u64 val) { write_sysreg(val, cntp_ctl_el0); + isb(); } struct timer_info { @@ -181,7 +187,6 @@ static bool test_cval_10msec(struct timer_info *info) before_timer = info->read_counter(); info->write_cval(before_timer + time_10ms); info->write_ctl(ARCH_TIMER_CTL_ENABLE); - isb(); /* Wait for the timer to fire */ while (!(info->read_ctl() & ARCH_TIMER_CTL_ISTATUS)) @@ -217,11 +222,9 @@ static void test_timer(struct timer_info *info) /* Enable the timer, but schedule it for much later */ info->write_cval(later); info->write_ctl(ARCH_TIMER_CTL_ENABLE); - isb(); report(!gic_timer_pending(info), "not pending before"); info->write_cval(now - 1); - isb(); report(gic_timer_pending(info), "interrupt signal pending"); /* Disable the timer again and prepare to take interrupts */ From patchwork Sat Apr 4 14:36:56 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Andrew Jones X-Patchwork-Id: 11474319 Return-Path: Received: from mail.kernel.org (pdx-korg-mail-1.web.codeaurora.org [172.30.200.123]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id CAD26912 for ; Sat, 4 Apr 2020 14:38:11 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id A9E2F2070E for ; Sat, 4 Apr 2020 14:38:11 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (1024-bit key) header.d=redhat.com header.i=@redhat.com header.b="FQ2jQCIB" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726467AbgDDOiK (ORCPT ); Sat, 4 Apr 2020 10:38:10 -0400 Received: from us-smtp-1.mimecast.com ([207.211.31.81]:49801 "EHLO us-smtp-delivery-1.mimecast.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S1726189AbgDDOh5 (ORCPT ); Sat, 4 Apr 2020 10:37:57 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1586011075; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=UcAnXTLK05SgTXUHXQBKYPlI5GJyG0mw92B1RM6BqXM=; b=FQ2jQCIB7/O+8KkkIi/xlSbF3Av+8QgxTZhpYClC1LOpUqLdUqVfn4eUxnzeqSD3QCI9mg eZK9FfIuwBUitpg13JKzL9eC5mxAGQlxXQiyC+Alom6OyRaXNAkSa9FEQfyBsFmyYMd2mm ixPHtn/P0sUMw6g/odYPWoGbPv4x6pQ= Received: from mimecast-mx01.redhat.com (mimecast-mx01.redhat.com [209.132.183.4]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-143-Amhc2xJtMUmRaY-ktwU_mQ-1; Sat, 04 Apr 2020 10:37:53 -0400 X-MC-Unique: Amhc2xJtMUmRaY-ktwU_mQ-1 Received: from smtp.corp.redhat.com (int-mx01.intmail.prod.int.phx2.redhat.com [10.5.11.11]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id A1A798024D0; Sat, 4 Apr 2020 14:37:48 +0000 (UTC) Received: from kamzik.brq.redhat.com (unknown [10.40.192.30]) by smtp.corp.redhat.com (Postfix) with ESMTP id E30F09B912; Sat, 4 Apr 2020 14:37:46 +0000 (UTC) From: Andrew Jones To: pbonzini@redhat.com Cc: kvm@vger.kernel.org, kvmarm@lists.cs.columbia.edu, Alexandru Elisei Subject: [PULL kvm-unit-tests 04/39] arm64: timer: Add ISB before reading the counter value Date: Sat, 4 Apr 2020 16:36:56 +0200 Message-Id: <20200404143731.208138-5-drjones@redhat.com> In-Reply-To: <20200404143731.208138-1-drjones@redhat.com> References: <20200404143731.208138-1-drjones@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.11 Sender: kvm-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: kvm@vger.kernel.org From: Alexandru Elisei Reads of the physical counter and the virtual counter registers "can occur speculatively and out of order relative to other instructions executed on the same PE" [1, 2]. There is no theoretical limit to the number of instructions that the CPU can reorder and we use the counter value to program the timer to fire in the future. Add an ISB before reading the counter to make sure the read instruction is not reordered too long in the past with regard to the instruction that programs the timer alarm, thus causing the timer to fire unexpectedly. This matches what Linux does (see arch/arm64/include/asm/arch_timer.h). Because we use the counter value to program the timer, we create a register dependency [3] between the value that we read and the value that we write to CVAL and thus we don't need a barrier after the read. Linux does things differently because the read needs to be ordered with regard to a memory load (more information in commit 75a19a0202db ("arm64: arch_timer: Ensure counter register reads occur with seqlock held")). This also matches what we already do in get_cntvct from lib/arm{,64}/asm/processor.h. [1] ARM DDI 0487E.a, section D11.2.1 [2] ARM DDI 0487E.a, section D11.2.2 [3] ARM DDI 0486E.a, section B2.3.2 Signed-off-by: Alexandru Elisei Signed-off-by: Andrew Jones --- arm/timer.c | 2 ++ 1 file changed, 2 insertions(+) diff --git a/arm/timer.c b/arm/timer.c index c6ea108cfa4b..e758e84855c3 100644 --- a/arm/timer.c +++ b/arm/timer.c @@ -30,6 +30,7 @@ static void ptimer_unsupported_handler(struct pt_regs *regs, unsigned int esr) static u64 read_vtimer_counter(void) { + isb(); return read_sysreg(cntvct_el0); } @@ -68,6 +69,7 @@ static void write_vtimer_ctl(u64 val) static u64 read_ptimer_counter(void) { + isb(); return read_sysreg(cntpct_el0); } From patchwork Sat Apr 4 14:36:57 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Andrew Jones X-Patchwork-Id: 11474307 Return-Path: Received: from mail.kernel.org (pdx-korg-mail-1.web.codeaurora.org [172.30.200.123]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id BFC02912 for ; Sat, 4 Apr 2020 14:38:01 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id 94054206F5 for ; Sat, 4 Apr 2020 14:38:01 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (1024-bit key) header.d=redhat.com header.i=@redhat.com header.b="Q5dJRyAo" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726428AbgDDOiA (ORCPT ); Sat, 4 Apr 2020 10:38:00 -0400 Received: from us-smtp-2.mimecast.com ([207.211.31.81]:30047 "EHLO us-smtp-delivery-1.mimecast.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S1726229AbgDDOh5 (ORCPT ); Sat, 4 Apr 2020 10:37:57 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1586011075; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=Euu3Q40ZKuRWEaooJhTwQlVK70xJGz+tBDjXBAOUp2U=; b=Q5dJRyAoXwx7ZODsuaMB03Vm3ZG1t+k+oM0VNa4/EuupMy/t7pl+IcPNOvo8ZROj/EdVWn 3RBUWcwb92lRXKY9E5uS3T8lGrtX5rSmfbiOeQHm9XtVdl8T3gsdra0qKWa3ENi1AHD8YB basY5aujSMY3HynHHO89ZW5JUeDlNE4= Received: from mimecast-mx01.redhat.com (mimecast-mx01.redhat.com [209.132.183.4]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-189--hQdh5ltMr2zW6mDooqKXg-1; Sat, 04 Apr 2020 10:37:53 -0400 X-MC-Unique: -hQdh5ltMr2zW6mDooqKXg-1 Received: from smtp.corp.redhat.com (int-mx01.intmail.prod.int.phx2.redhat.com [10.5.11.11]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id 3743518AB2E3; Sat, 4 Apr 2020 14:37:51 +0000 (UTC) Received: from kamzik.brq.redhat.com (unknown [10.40.192.30]) by smtp.corp.redhat.com (Postfix) with ESMTP id 2549F9B912; Sat, 4 Apr 2020 14:37:48 +0000 (UTC) From: Andrew Jones To: pbonzini@redhat.com Cc: kvm@vger.kernel.org, kvmarm@lists.cs.columbia.edu, Alexandru Elisei , Andre Przywara Subject: [PULL kvm-unit-tests 05/39] arm64: timer: Make irq_received volatile Date: Sat, 4 Apr 2020 16:36:57 +0200 Message-Id: <20200404143731.208138-6-drjones@redhat.com> In-Reply-To: <20200404143731.208138-1-drjones@redhat.com> References: <20200404143731.208138-1-drjones@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.11 Sender: kvm-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: kvm@vger.kernel.org From: Alexandru Elisei The irq_received field is modified by the interrupt handler. Make it volatile so that the compiler doesn't reorder accesses with regard to the instruction that will be causing the interrupt. Suggested-by: Andre Przywara Signed-off-by: Alexandru Elisei Signed-off-by: Andrew Jones --- arm/timer.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/arm/timer.c b/arm/timer.c index e758e84855c3..82f891147b35 100644 --- a/arm/timer.c +++ b/arm/timer.c @@ -109,7 +109,7 @@ static void write_ptimer_ctl(u64 val) struct timer_info { u32 irq; u32 irq_flags; - bool irq_received; + volatile bool irq_received; u64 (*read_counter)(void); u64 (*read_cval)(void); void (*write_cval)(u64); From patchwork Sat Apr 4 14:36:58 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Andrew Jones X-Patchwork-Id: 11474303 Return-Path: Received: from mail.kernel.org (pdx-korg-mail-1.web.codeaurora.org [172.30.200.123]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 9FB6215AB for ; Sat, 4 Apr 2020 14:37:58 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id 7DF9A2071C for ; Sat, 4 Apr 2020 14:37:58 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (1024-bit key) header.d=redhat.com header.i=@redhat.com header.b="G1mVHwVu" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726377AbgDDOh6 (ORCPT ); Sat, 4 Apr 2020 10:37:58 -0400 Received: from us-smtp-2.mimecast.com ([207.211.31.81]:30531 "EHLO us-smtp-delivery-1.mimecast.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S1726364AbgDDOh5 (ORCPT ); Sat, 4 Apr 2020 10:37:57 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1586011076; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=tlCWhqWlWCHWkziqDK8HtBNiS2KEZarZ4cSvHaSV7Js=; b=G1mVHwVunbNPgvi57mo7cFVLfYl+oszILfWI7/onqLfZUz3KpECCI0GBRFeZ8WZrN/eZGY vY8KA45KGfonQVamdW0/NNF5sdx3XGa8AEHRD5FMYdTvfANrfzngzH951Zoi6tkCBaOlAf 1WKVu1ppnV1gmmX/u8YactKTz/jesDs= Received: from mimecast-mx01.redhat.com (mimecast-mx01.redhat.com [209.132.183.4]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-339-cb8AfRe9PEyLucJRgo82ZA-1; Sat, 04 Apr 2020 10:37:54 -0400 X-MC-Unique: cb8AfRe9PEyLucJRgo82ZA-1 Received: from smtp.corp.redhat.com (int-mx01.intmail.prod.int.phx2.redhat.com [10.5.11.11]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id 94719801F9D; Sat, 4 Apr 2020 14:37:53 +0000 (UTC) Received: from kamzik.brq.redhat.com (unknown [10.40.192.30]) by smtp.corp.redhat.com (Postfix) with ESMTP id AE8A81147DA; Sat, 4 Apr 2020 14:37:51 +0000 (UTC) From: Andrew Jones To: pbonzini@redhat.com Cc: kvm@vger.kernel.org, kvmarm@lists.cs.columbia.edu, Alexandru Elisei Subject: [PULL kvm-unit-tests 06/39] arm64: timer: EOIR the interrupt after masking the timer Date: Sat, 4 Apr 2020 16:36:58 +0200 Message-Id: <20200404143731.208138-7-drjones@redhat.com> In-Reply-To: <20200404143731.208138-1-drjones@redhat.com> References: <20200404143731.208138-1-drjones@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.11 Sender: kvm-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: kvm@vger.kernel.org From: Alexandru Elisei Writing to the EOIR register before masking the HW mapped timer interrupt can cause taking another timer interrupt immediately after exception return. This doesn't happen all the time, because KVM reevaluates the state of pending HW mapped level sensitive interrupts on each guest exit. If the second interrupt is pending and a guest exit occurs after masking the timer interrupt and before the ERET (which restores PSTATE.I), then KVM removes it. Move the write after the IMASK bit has been set to prevent this from happening. Signed-off-by: Alexandru Elisei Signed-off-by: Andrew Jones --- arm/timer.c | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/arm/timer.c b/arm/timer.c index 82f891147b35..b6f9dd10162d 100644 --- a/arm/timer.c +++ b/arm/timer.c @@ -157,19 +157,20 @@ static void irq_handler(struct pt_regs *regs) u32 irqstat = gic_read_iar(); u32 irqnr = gic_iar_irqnr(irqstat); - if (irqnr != GICC_INT_SPURIOUS) - gic_write_eoir(irqstat); - if (irqnr == PPI(vtimer_info.irq)) { info = &vtimer_info; } else if (irqnr == PPI(ptimer_info.irq)) { info = &ptimer_info; } else { + if (irqnr != GICC_INT_SPURIOUS) + gic_write_eoir(irqstat); report_info("Unexpected interrupt: %d\n", irqnr); return; } info->write_ctl(ARCH_TIMER_CTL_IMASK | ARCH_TIMER_CTL_ENABLE); + gic_write_eoir(irqstat); + info->irq_received = true; } From patchwork Sat Apr 4 14:36:59 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Andrew Jones X-Patchwork-Id: 11474313 Return-Path: Received: from mail.kernel.org (pdx-korg-mail-1.web.codeaurora.org [172.30.200.123]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 0B688912 for ; Sat, 4 Apr 2020 14:38:06 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id DFC712071C for ; Sat, 4 Apr 2020 14:38:05 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (1024-bit key) header.d=redhat.com header.i=@redhat.com header.b="G9OMcbSB" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726420AbgDDOiE (ORCPT ); Sat, 4 Apr 2020 10:38:04 -0400 Received: from us-smtp-2.mimecast.com ([205.139.110.61]:52080 "EHLO us-smtp-delivery-1.mimecast.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S1726395AbgDDOiA (ORCPT ); Sat, 4 Apr 2020 10:38:00 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1586011079; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=dKH8kqeRHPgwOpfK642cVQ9Bs8jNBiXwoN4mILH3dyQ=; b=G9OMcbSBojgp2LmQ/tex5A3w8isKAhHBHcGeEluKddNrMg1lWQ5UKjn7hLJ/yVhGlzndnn WYOgA2IblUSIaBfD2ekJX2UNfiafg6OKxuyG53pq7p5+8BteLUJFD1+/X3ZusMlOw0+qcf xXHCGAu1gtcymV3cmBSbdmSSLG0TWvI= Received: from mimecast-mx01.redhat.com (mimecast-mx01.redhat.com [209.132.183.4]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-30--RQ6u3H-Nea8gZAmXtbi-Q-1; Sat, 04 Apr 2020 10:37:56 -0400 X-MC-Unique: -RQ6u3H-Nea8gZAmXtbi-Q-1 Received: from smtp.corp.redhat.com (int-mx01.intmail.prod.int.phx2.redhat.com [10.5.11.11]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id CDD9418AB2C2; Sat, 4 Apr 2020 14:37:55 +0000 (UTC) Received: from kamzik.brq.redhat.com (unknown [10.40.192.30]) by smtp.corp.redhat.com (Postfix) with ESMTP id 16CFB9B912; Sat, 4 Apr 2020 14:37:53 +0000 (UTC) From: Andrew Jones To: pbonzini@redhat.com Cc: kvm@vger.kernel.org, kvmarm@lists.cs.columbia.edu, Alexandru Elisei Subject: [PULL kvm-unit-tests 07/39] arm64: timer: Wait for the GIC to sample timer interrupt state Date: Sat, 4 Apr 2020 16:36:59 +0200 Message-Id: <20200404143731.208138-8-drjones@redhat.com> In-Reply-To: <20200404143731.208138-1-drjones@redhat.com> References: <20200404143731.208138-1-drjones@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.11 Sender: kvm-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: kvm@vger.kernel.org From: Alexandru Elisei There is a delay between the timer asserting the interrupt and the GIC sampling the interrupt state. Let's take that into account when we are checking if the timer interrupt is pending (or not) at the GIC level. An interrupt can be pending or active and pending [1,2]. Let's be precise and check that the interrupt is actually pending, not active and pending. [1] ARM IHI 0048B.b, section 1.4.1 [2] ARM IHI 0069E, section 1.2.2 Signed-off-by: Alexandru Elisei Signed-off-by: Andrew Jones --- arm/timer.c | 43 ++++++++++++++++++++++++++++++++++++++----- arm/unittests.cfg | 2 +- 2 files changed, 39 insertions(+), 6 deletions(-) diff --git a/arm/timer.c b/arm/timer.c index b6f9dd10162d..ba7e8c6a90ed 100644 --- a/arm/timer.c +++ b/arm/timer.c @@ -8,6 +8,7 @@ #include #include #include +#include #include #include #include @@ -16,6 +17,14 @@ #define ARCH_TIMER_CTL_IMASK (1 << 1) #define ARCH_TIMER_CTL_ISTATUS (1 << 2) +enum gic_state { + GIC_STATE_INACTIVE, + GIC_STATE_PENDING, + GIC_STATE_ACTIVE, + GIC_STATE_ACTIVE_PENDING, +}; + +static void *gic_isactiver; static void *gic_ispendr; static void *gic_isenabler; static void *gic_icenabler; @@ -174,9 +183,28 @@ static void irq_handler(struct pt_regs *regs) info->irq_received = true; } -static bool gic_timer_pending(struct timer_info *info) +static enum gic_state gic_timer_state(struct timer_info *info) { - return readl(gic_ispendr) & (1 << PPI(info->irq)); + enum gic_state state = GIC_STATE_INACTIVE; + int i; + bool pending, active; + + /* Wait for up to 1s for the GIC to sample the interrupt. */ + for (i = 0; i < 10; i++) { + pending = readl(gic_ispendr) & (1 << PPI(info->irq)); + active = readl(gic_isactiver) & (1 << PPI(info->irq)); + if (!active && !pending) + state = GIC_STATE_INACTIVE; + if (pending) + state = GIC_STATE_PENDING; + if (active) + state = GIC_STATE_ACTIVE; + if (active && pending) + state = GIC_STATE_ACTIVE_PENDING; + mdelay(100); + } + + return state; } static bool test_cval_10msec(struct timer_info *info) @@ -225,15 +253,18 @@ static void test_timer(struct timer_info *info) /* Enable the timer, but schedule it for much later */ info->write_cval(later); info->write_ctl(ARCH_TIMER_CTL_ENABLE); - report(!gic_timer_pending(info), "not pending before"); + report(gic_timer_state(info) == GIC_STATE_INACTIVE, + "not pending before"); info->write_cval(now - 1); - report(gic_timer_pending(info), "interrupt signal pending"); + report(gic_timer_state(info) == GIC_STATE_PENDING, + "interrupt signal pending"); /* Disable the timer again and prepare to take interrupts */ info->write_ctl(0); set_timer_irq_enabled(info, true); - report(!gic_timer_pending(info), "interrupt signal no longer pending"); + report(gic_timer_state(info) == GIC_STATE_INACTIVE, + "interrupt signal no longer pending"); report(test_cval_10msec(info), "latency within 10 ms"); report(info->irq_received, "interrupt received"); @@ -307,11 +338,13 @@ static void test_init(void) switch (gic_version()) { case 2: + gic_isactiver = gicv2_dist_base() + GICD_ISACTIVER; gic_ispendr = gicv2_dist_base() + GICD_ISPENDR; gic_isenabler = gicv2_dist_base() + GICD_ISENABLER; gic_icenabler = gicv2_dist_base() + GICD_ICENABLER; break; case 3: + gic_isactiver = gicv3_sgi_base() + GICD_ISACTIVER; gic_ispendr = gicv3_sgi_base() + GICD_ISPENDR; gic_isenabler = gicv3_sgi_base() + GICR_ISENABLER0; gic_icenabler = gicv3_sgi_base() + GICR_ICENABLER0; diff --git a/arm/unittests.cfg b/arm/unittests.cfg index daeb5a09ad39..1f1bb24d9d13 100644 --- a/arm/unittests.cfg +++ b/arm/unittests.cfg @@ -132,7 +132,7 @@ groups = psci [timer] file = timer.flat groups = timer -timeout = 2s +timeout = 8s arch = arm64 # Exit tests From patchwork Sat Apr 4 14:37:00 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Andrew Jones X-Patchwork-Id: 11474309 Return-Path: Received: from mail.kernel.org (pdx-korg-mail-1.web.codeaurora.org [172.30.200.123]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id CE0AB1392 for ; Sat, 4 Apr 2020 14:38:03 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id ACF912071C for ; Sat, 4 Apr 2020 14:38:03 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (1024-bit key) header.d=redhat.com header.i=@redhat.com header.b="FKKIb0q1" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726417AbgDDOiC (ORCPT ); Sat, 4 Apr 2020 10:38:02 -0400 Received: from us-smtp-delivery-1.mimecast.com ([205.139.110.120]:60013 "EHLO us-smtp-1.mimecast.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S1726436AbgDDOiC (ORCPT ); Sat, 4 Apr 2020 10:38:02 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1586011081; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=aBG/mcHOc4lZna+l3/TBlcARw6Oe4Vd9Cbmo3iln5tI=; b=FKKIb0q1ZMKzjqIQ/ItTXUAu3Aa8gr5n+UE3zogGCDPO6pO0gdN6f949MhSJRmgDHuSzlu uf/hJYCtCnCvobZPpakuI6fZd/hfUi1cQSWLvHP/lci348G8oySGQh/XLyilP/9vzzRUDV V2mu8FxX82byzT4qFbKsOfXtd5gDt7s= Received: from mimecast-mx01.redhat.com (mimecast-mx01.redhat.com [209.132.183.4]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-318-3KcyUQyyMfahtAk-OZ6fjw-1; Sat, 04 Apr 2020 10:37:59 -0400 X-MC-Unique: 3KcyUQyyMfahtAk-OZ6fjw-1 Received: from smtp.corp.redhat.com (int-mx01.intmail.prod.int.phx2.redhat.com [10.5.11.11]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id 34D3C8017F3; Sat, 4 Apr 2020 14:37:58 +0000 (UTC) Received: from kamzik.brq.redhat.com (unknown [10.40.192.30]) by smtp.corp.redhat.com (Postfix) with ESMTP id 4E1F69B912; Sat, 4 Apr 2020 14:37:56 +0000 (UTC) From: Andrew Jones To: pbonzini@redhat.com Cc: kvm@vger.kernel.org, kvmarm@lists.cs.columbia.edu, Alexandru Elisei Subject: [PULL kvm-unit-tests 08/39] arm64: timer: Check the timer interrupt state Date: Sat, 4 Apr 2020 16:37:00 +0200 Message-Id: <20200404143731.208138-9-drjones@redhat.com> In-Reply-To: <20200404143731.208138-1-drjones@redhat.com> References: <20200404143731.208138-1-drjones@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.11 Sender: kvm-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: kvm@vger.kernel.org From: Alexandru Elisei We check that the interrupt is pending (or not) at the GIC level, but we don't check if the timer is asserting it (or not). Let's make sure we don't run into a strange situation where the two devices' states aren't synchronized. Coincidently, the "interrupt signal no longer pending" test fails for non-emulated timers (i.e, the virtual timer on a non-vhe host) if the host kernel doesn't have patch 16e604a437c89 ("KVM: arm/arm64: vgic: Reevaluate level sensitive interrupts on enable"). Signed-off-by: Alexandru Elisei Signed-off-by: Andrew Jones --- arm/timer.c | 15 +++++++++++---- 1 file changed, 11 insertions(+), 4 deletions(-) diff --git a/arm/timer.c b/arm/timer.c index ba7e8c6a90ed..35038f2bae57 100644 --- a/arm/timer.c +++ b/arm/timer.c @@ -183,6 +183,13 @@ static void irq_handler(struct pt_regs *regs) info->irq_received = true; } +/* Check that the timer condition is met. */ +static bool timer_pending(struct timer_info *info) +{ + return (info->read_ctl() & ARCH_TIMER_CTL_ENABLE) && + (info->read_ctl() & ARCH_TIMER_CTL_ISTATUS); +} + static enum gic_state gic_timer_state(struct timer_info *info) { enum gic_state state = GIC_STATE_INACTIVE; @@ -220,7 +227,7 @@ static bool test_cval_10msec(struct timer_info *info) info->write_ctl(ARCH_TIMER_CTL_ENABLE); /* Wait for the timer to fire */ - while (!(info->read_ctl() & ARCH_TIMER_CTL_ISTATUS)) + while (!timer_pending(info)) ; /* It fired, check how long it took */ @@ -253,17 +260,17 @@ static void test_timer(struct timer_info *info) /* Enable the timer, but schedule it for much later */ info->write_cval(later); info->write_ctl(ARCH_TIMER_CTL_ENABLE); - report(gic_timer_state(info) == GIC_STATE_INACTIVE, + report(!timer_pending(info) && gic_timer_state(info) == GIC_STATE_INACTIVE, "not pending before"); info->write_cval(now - 1); - report(gic_timer_state(info) == GIC_STATE_PENDING, + report(timer_pending(info) && gic_timer_state(info) == GIC_STATE_PENDING, "interrupt signal pending"); /* Disable the timer again and prepare to take interrupts */ info->write_ctl(0); set_timer_irq_enabled(info, true); - report(gic_timer_state(info) == GIC_STATE_INACTIVE, + report(!timer_pending(info) && gic_timer_state(info) == GIC_STATE_INACTIVE, "interrupt signal no longer pending"); report(test_cval_10msec(info), "latency within 10 ms"); From patchwork Sat Apr 4 14:37:01 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Andrew Jones X-Patchwork-Id: 11474315 Return-Path: Received: from mail.kernel.org (pdx-korg-mail-1.web.codeaurora.org [172.30.200.123]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 463CA1392 for ; Sat, 4 Apr 2020 14:38:07 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id 24DF4206F5 for ; Sat, 4 Apr 2020 14:38:07 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (1024-bit key) header.d=redhat.com header.i=@redhat.com header.b="J8/l/fgD" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726476AbgDDOiG (ORCPT ); Sat, 4 Apr 2020 10:38:06 -0400 Received: from us-smtp-delivery-1.mimecast.com ([207.211.31.120]:31426 "EHLO us-smtp-1.mimecast.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S1726396AbgDDOiE (ORCPT ); Sat, 4 Apr 2020 10:38:04 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1586011083; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=dPpw8Y0BbKXD+s5EjzvlI+dw+lnTfzQ1bENX5180HXQ=; b=J8/l/fgDn23+CANFmd8RMYfjN0hsrcc915dWsN9lCzoGVJTv8rCCgkGiWsoJOJYQx2uDax CvzmVXJA29hNuy+k/VgWIPjvc6THcz3PKsp0ga8auzJDaG7eSut3SWOdZn3hgBC0ByqM11 w4OLHn5dIb6Mr3ZMacj5EnIhuaPnWqk= Received: from mimecast-mx01.redhat.com (mimecast-mx01.redhat.com [209.132.183.4]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-465-Cg06DVXyPue4tgTxxAL-PA-1; Sat, 04 Apr 2020 10:38:01 -0400 X-MC-Unique: Cg06DVXyPue4tgTxxAL-PA-1 Received: from smtp.corp.redhat.com (int-mx01.intmail.prod.int.phx2.redhat.com [10.5.11.11]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id 6C188800D4E; Sat, 4 Apr 2020 14:38:00 +0000 (UTC) Received: from kamzik.brq.redhat.com (unknown [10.40.192.30]) by smtp.corp.redhat.com (Postfix) with ESMTP id AAC4D1147DA; Sat, 4 Apr 2020 14:37:58 +0000 (UTC) From: Andrew Jones To: pbonzini@redhat.com Cc: kvm@vger.kernel.org, kvmarm@lists.cs.columbia.edu, Alexandru Elisei Subject: [PULL kvm-unit-tests 09/39] arm64: timer: Test behavior when timer disabled or masked Date: Sat, 4 Apr 2020 16:37:01 +0200 Message-Id: <20200404143731.208138-10-drjones@redhat.com> In-Reply-To: <20200404143731.208138-1-drjones@redhat.com> References: <20200404143731.208138-1-drjones@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.11 Sender: kvm-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: kvm@vger.kernel.org From: Alexandru Elisei When the timer is disabled (the *_CTL_EL0.ENABLE bit is clear) or the timer interrupt is masked at the timer level (the *_CTL_EL0.IMASK bit is set), timer interrupts must not be pending or asserted by the VGIC. However, only when the timer interrupt is masked, we can still check that the timer condition is met by reading the *_CTL_EL0.ISTATUS bit. This test was used to discover a bug and test the fix introduced by KVM commit 16e604a437c8 ("KVM: arm/arm64: vgic: Reevaluate level sensitive interrupts on enable"). Signed-off-by: Alexandru Elisei Signed-off-by: Andrew Jones --- arm/timer.c | 7 +++++++ arm/unittests.cfg | 2 +- 2 files changed, 8 insertions(+), 1 deletion(-) diff --git a/arm/timer.c b/arm/timer.c index 35038f2bae57..dea364f5355d 100644 --- a/arm/timer.c +++ b/arm/timer.c @@ -269,10 +269,17 @@ static void test_timer(struct timer_info *info) /* Disable the timer again and prepare to take interrupts */ info->write_ctl(0); + info->irq_received = false; set_timer_irq_enabled(info, true); + report(!info->irq_received, "no interrupt when timer is disabled"); report(!timer_pending(info) && gic_timer_state(info) == GIC_STATE_INACTIVE, "interrupt signal no longer pending"); + info->write_cval(now - 1); + info->write_ctl(ARCH_TIMER_CTL_ENABLE | ARCH_TIMER_CTL_IMASK); + report(timer_pending(info) && gic_timer_state(info) == GIC_STATE_INACTIVE, + "interrupt signal not pending"); + report(test_cval_10msec(info), "latency within 10 ms"); report(info->irq_received, "interrupt received"); diff --git a/arm/unittests.cfg b/arm/unittests.cfg index 1f1bb24d9d13..017958d28ffd 100644 --- a/arm/unittests.cfg +++ b/arm/unittests.cfg @@ -132,7 +132,7 @@ groups = psci [timer] file = timer.flat groups = timer -timeout = 8s +timeout = 10s arch = arm64 # Exit tests From patchwork Sat Apr 4 14:37:02 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Andrew Jones X-Patchwork-Id: 11474317 Return-Path: Received: from mail.kernel.org (pdx-korg-mail-1.web.codeaurora.org [172.30.200.123]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 0986E1392 for ; Sat, 4 Apr 2020 14:38:10 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id D0D14206F5 for ; Sat, 4 Apr 2020 14:38:09 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (1024-bit key) header.d=redhat.com header.i=@redhat.com header.b="Ll6pGOCd" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726314AbgDDOiI (ORCPT ); Sat, 4 Apr 2020 10:38:08 -0400 Received: from us-smtp-1.mimecast.com ([205.139.110.61]:27483 "EHLO us-smtp-delivery-1.mimecast.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S1726477AbgDDOiI (ORCPT ); Sat, 4 Apr 2020 10:38:08 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1586011086; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=esT0Q0gioFinX15SP781reoHfr6dcdqw3vZtq2Y8jjs=; b=Ll6pGOCdX5fjWvn8i7hKpxzXRwyzKfBrSgIyV1T2jFj+iepnn4U2jR/YULO1D1LQL3IIWR wRXHBaCi1DBeu1GaO9wfNTxSEKbshrakr8IxQtw9X5RKI+7koNgnD1LwMVLGLpCLLHKyxX AhTKFN7L84BZcM/6PpLF7u1r79ePEso= Received: from mimecast-mx01.redhat.com (mimecast-mx01.redhat.com [209.132.183.4]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-240-o7XYZwL8OQySIINZUy42DA-1; Sat, 04 Apr 2020 10:38:03 -0400 X-MC-Unique: o7XYZwL8OQySIINZUy42DA-1 Received: from smtp.corp.redhat.com (int-mx01.intmail.prod.int.phx2.redhat.com [10.5.11.11]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id BE7AD14E0; Sat, 4 Apr 2020 14:38:02 +0000 (UTC) Received: from kamzik.brq.redhat.com (unknown [10.40.192.30]) by smtp.corp.redhat.com (Postfix) with ESMTP id E311D9B912; Sat, 4 Apr 2020 14:38:00 +0000 (UTC) From: Andrew Jones To: pbonzini@redhat.com Cc: kvm@vger.kernel.org, kvmarm@lists.cs.columbia.edu, Alexandru Elisei Subject: [PULL kvm-unit-tests 10/39] arm/arm64: Perform dcache clean + invalidate after turning MMU off Date: Sat, 4 Apr 2020 16:37:02 +0200 Message-Id: <20200404143731.208138-11-drjones@redhat.com> In-Reply-To: <20200404143731.208138-1-drjones@redhat.com> References: <20200404143731.208138-1-drjones@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.11 Sender: kvm-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: kvm@vger.kernel.org From: Alexandru Elisei When the MMU is off, data accesses are to Device nGnRnE memory on arm64 [1] or to Strongly-Ordered memory on arm [2]. This means that the accesses are non-cacheable. Perform a dcache clean to PoC so we can read the newer values from the cache after we turn the MMU off, instead of the stale values from memory. Perform an invalidation so we can access the data written to memory after we turn the MMU back on. This prevents reading back the stale values we cleaned from the cache when we turned the MMU off. Data caches are PIPT and the VAs are translated using the current translation tables, or an identity mapping (what Arm calls a "flat mapping") when the MMU is off [1, 2]. Do the clean + invalidate when the MMU is off so we don't depend on the current translation tables and we can make sure that the operation applies to the entire physical memory. The patch was tested by hacking arm/selftest.c: +#include +#include int main(int argc, char **argv) { + int *x = alloc_page(); + report_prefix_push("selftest"); + *x = 0x42; + mmu_disable(); + report(*x == 0x42, "read back value written with MMU on"); + *x = 0x50; + mmu_enable(current_thread_info()->pgtable); + report(*x == 0x50, "read back value written with MMU off"); + if (argc < 2) report_abort("no test specified"); Without the fix, the first report fails, and the test usually hangs before the second report. This is because mmu_enable pushes the LR register on the stack when the MMU is off, which means that the value will be written to memory. However, after asm_mmu_enable, the MMU is enabled, and we read it back from the dcache, thus getting garbage. With the fix, the two reports pass. [1] ARM DDI 0487E.a, section D5.2.9 [2] ARM DDI 0406C.d, section B3.2.1 Signed-off-by: Alexandru Elisei Signed-off-by: Andrew Jones --- arm/cstart.S | 22 ++++++++++++++++++++++ arm/cstart64.S | 23 +++++++++++++++++++++++ lib/arm/asm/processor.h | 13 +++++++++++++ lib/arm/setup.c | 8 ++++++++ lib/arm64/asm/processor.h | 12 ++++++++++++ 5 files changed, 78 insertions(+) diff --git a/arm/cstart.S b/arm/cstart.S index e54e380e0d53..ef936ae2f874 100644 --- a/arm/cstart.S +++ b/arm/cstart.S @@ -197,6 +197,20 @@ asm_mmu_enable: mov pc, lr +.macro dcache_clean_inval domain, start, end, tmp1, tmp2 + ldr \tmp1, =dcache_line_size + ldr \tmp1, [\tmp1] + sub \tmp2, \tmp1, #1 + bic \start, \start, \tmp2 +9998: + /* DCCIMVAC */ + mcr p15, 0, \start, c7, c14, 1 + add \start, \start, \tmp1 + cmp \start, \end + blo 9998b + dsb \domain +.endm + .globl asm_mmu_disable asm_mmu_disable: /* SCTLR */ @@ -204,6 +218,14 @@ asm_mmu_disable: bic r0, #CR_M mcr p15, 0, r0, c1, c0, 0 isb + + ldr r0, =__phys_offset + ldr r0, [r0] + ldr r1, =__phys_end + ldr r1, [r1] + dcache_clean_inval sy, r0, r1, r2, r3 + isb + mov pc, lr /* diff --git a/arm/cstart64.S b/arm/cstart64.S index e5a561ea2e39..ffdd49f73ddd 100644 --- a/arm/cstart64.S +++ b/arm/cstart64.S @@ -193,12 +193,35 @@ asm_mmu_enable: ret +/* Taken with small changes from arch/arm64/incluse/asm/assembler.h */ +.macro dcache_by_line_op op, domain, start, end, tmp1, tmp2 + adrp \tmp1, dcache_line_size + ldr \tmp1, [\tmp1, :lo12:dcache_line_size] + sub \tmp2, \tmp1, #1 + bic \start, \start, \tmp2 +9998: + dc \op , \start + add \start, \start, \tmp1 + cmp \start, \end + b.lo 9998b + dsb \domain +.endm + .globl asm_mmu_disable asm_mmu_disable: mrs x0, sctlr_el1 bic x0, x0, SCTLR_EL1_M msr sctlr_el1, x0 isb + + /* Clean + invalidate the entire memory */ + adrp x0, __phys_offset + ldr x0, [x0, :lo12:__phys_offset] + adrp x1, __phys_end + ldr x1, [x1, :lo12:__phys_end] + dcache_by_line_op civac, sy, x0, x1, x2, x3 + isb + ret /* diff --git a/lib/arm/asm/processor.h b/lib/arm/asm/processor.h index a8c4628da818..1e1132dafd2b 100644 --- a/lib/arm/asm/processor.h +++ b/lib/arm/asm/processor.h @@ -9,6 +9,11 @@ #include #include +#define CTR_DMINLINE_SHIFT 16 +#define CTR_DMINLINE_MASK (0xf << 16) +#define CTR_DMINLINE(x) \ + (((x) & CTR_DMINLINE_MASK) >> CTR_DMINLINE_SHIFT) + enum vector { EXCPTN_RST, EXCPTN_UND, @@ -64,6 +69,7 @@ extern bool is_user(void); #define CNTVCT __ACCESS_CP15_64(1, c14) #define CNTFRQ __ACCESS_CP15(c14, 0, c0, 0) +#define CTR __ACCESS_CP15(c0, 0, c0, 1) static inline u64 get_cntvct(void) { @@ -76,4 +82,11 @@ static inline u32 get_cntfrq(void) return read_sysreg(CNTFRQ); } +static inline u32 get_ctr(void) +{ + return read_sysreg(CTR); +} + +extern u32 dcache_line_size; + #endif /* _ASMARM_PROCESSOR_H_ */ diff --git a/lib/arm/setup.c b/lib/arm/setup.c index 385e135f4865..418b4e58a5f8 100644 --- a/lib/arm/setup.c +++ b/lib/arm/setup.c @@ -20,6 +20,7 @@ #include #include #include +#include #include #include "io.h" @@ -38,6 +39,8 @@ static struct mem_region __initial_mem_regions[NR_INITIAL_MEM_REGIONS + 1]; struct mem_region *mem_regions = __initial_mem_regions; phys_addr_t __phys_offset, __phys_end; +u32 dcache_line_size; + int mpidr_to_cpu(uint64_t mpidr) { int i; @@ -66,6 +69,11 @@ static void cpu_init(void) ret = dt_for_each_cpu_node(cpu_set, NULL); assert(ret == 0); set_cpu_online(0, true); + /* + * DminLine is log2 of the number of words in the smallest cache line; a + * word is 4 bytes. + */ + dcache_line_size = 1 << (CTR_DMINLINE(get_ctr()) + 2); } unsigned int mem_region_get_flags(phys_addr_t paddr) diff --git a/lib/arm64/asm/processor.h b/lib/arm64/asm/processor.h index 1d9223f728a5..02665b84cc7e 100644 --- a/lib/arm64/asm/processor.h +++ b/lib/arm64/asm/processor.h @@ -16,6 +16,11 @@ #define SCTLR_EL1_A (1 << 1) #define SCTLR_EL1_M (1 << 0) +#define CTR_DMINLINE_SHIFT 16 +#define CTR_DMINLINE_MASK (0xf << 16) +#define CTR_DMINLINE(x) \ + (((x) & CTR_DMINLINE_MASK) >> CTR_DMINLINE_SHIFT) + #ifndef __ASSEMBLY__ #include #include @@ -105,5 +110,12 @@ static inline u32 get_cntfrq(void) return read_sysreg(cntfrq_el0); } +static inline u64 get_ctr(void) +{ + return read_sysreg(ctr_el0); +} + +extern u32 dcache_line_size; + #endif /* !__ASSEMBLY__ */ #endif /* _ASMARM64_PROCESSOR_H_ */ From patchwork Sat Apr 4 14:37:03 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Andrew Jones X-Patchwork-Id: 11474323 Return-Path: Received: from mail.kernel.org (pdx-korg-mail-1.web.codeaurora.org [172.30.200.123]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id AFA06912 for ; Sat, 4 Apr 2020 14:38:13 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id 83ECD2070E for ; Sat, 4 Apr 2020 14:38:13 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (1024-bit key) header.d=redhat.com header.i=@redhat.com header.b="FJEcvjRC" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726229AbgDDOiM (ORCPT ); Sat, 4 Apr 2020 10:38:12 -0400 Received: from us-smtp-delivery-1.mimecast.com ([207.211.31.120]:59854 "EHLO us-smtp-1.mimecast.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S1726189AbgDDOiL (ORCPT ); Sat, 4 Apr 2020 10:38:11 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1586011090; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=HJXgouF5hnW6c32QC5HW05D5OVof60jHODwykFGab7c=; b=FJEcvjRC3G/OSI/OrdjTEdAjCaoQYjzgxu8vTLxh7n7/fdnKokVJjjeYPRYclR/uVQ4nrZ WVvaW46L+jZlbNU07r4o6qGNgxI8vbbwlzN/8xLm/hSo7aOdZVCdKl+Cpg6UQYDSuqh/TL zPEfIO4ubS22z6RMgm269KPafFP3SLw= Received: from mimecast-mx01.redhat.com (mimecast-mx01.redhat.com [209.132.183.4]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-397-vZ5SYYPXO0q_xL4SSS9zSg-1; Sat, 04 Apr 2020 10:38:08 -0400 X-MC-Unique: vZ5SYYPXO0q_xL4SSS9zSg-1 Received: from smtp.corp.redhat.com (int-mx01.intmail.prod.int.phx2.redhat.com [10.5.11.11]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id 5085D107ACC7; Sat, 4 Apr 2020 14:38:07 +0000 (UTC) Received: from kamzik.brq.redhat.com (unknown [10.40.192.30]) by smtp.corp.redhat.com (Postfix) with ESMTP id 660F51147D3; Sat, 4 Apr 2020 14:38:03 +0000 (UTC) From: Andrew Jones To: pbonzini@redhat.com Cc: kvm@vger.kernel.org, kvmarm@lists.cs.columbia.edu, Zenghui Yu Subject: [PULL kvm-unit-tests 11/39] arm/arm64: gic: Move gic_state enumeration to asm/gic.h Date: Sat, 4 Apr 2020 16:37:03 +0200 Message-Id: <20200404143731.208138-12-drjones@redhat.com> In-Reply-To: <20200404143731.208138-1-drjones@redhat.com> References: <20200404143731.208138-1-drjones@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.11 Sender: kvm-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: kvm@vger.kernel.org From: Zenghui Yu The status of each interrupt are defined by the GIC architecture and maintained by GIC hardware. They're not specified to the timer HW. Let's move this software enumeration to a more proper place. Signed-off-by: Zenghui Yu Signed-off-by: Andrew Jones --- arm/timer.c | 7 ------- lib/arm/asm/gic.h | 7 +++++++ 2 files changed, 7 insertions(+), 7 deletions(-) diff --git a/arm/timer.c b/arm/timer.c index dea364f5355d..94543f231ba9 100644 --- a/arm/timer.c +++ b/arm/timer.c @@ -17,13 +17,6 @@ #define ARCH_TIMER_CTL_IMASK (1 << 1) #define ARCH_TIMER_CTL_ISTATUS (1 << 2) -enum gic_state { - GIC_STATE_INACTIVE, - GIC_STATE_PENDING, - GIC_STATE_ACTIVE, - GIC_STATE_ACTIVE_PENDING, -}; - static void *gic_isactiver; static void *gic_ispendr; static void *gic_isenabler; diff --git a/lib/arm/asm/gic.h b/lib/arm/asm/gic.h index 09826fd5bc29..a72e0cde4e9c 100644 --- a/lib/arm/asm/gic.h +++ b/lib/arm/asm/gic.h @@ -47,6 +47,13 @@ #ifndef __ASSEMBLY__ #include +enum gic_state { + GIC_STATE_INACTIVE, + GIC_STATE_PENDING, + GIC_STATE_ACTIVE, + GIC_STATE_ACTIVE_PENDING, +}; + /* * gic_init will try to find all known gics, and then * initialize the gic data for the one found. From patchwork Sat Apr 4 14:37:04 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Andrew Jones X-Patchwork-Id: 11474325 Return-Path: Received: from mail.kernel.org (pdx-korg-mail-1.web.codeaurora.org [172.30.200.123]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 718AD912 for ; Sat, 4 Apr 2020 14:38:17 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id 4F86C2071C for ; Sat, 4 Apr 2020 14:38:17 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (1024-bit key) header.d=redhat.com header.i=@redhat.com header.b="i0nZFb2v" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726484AbgDDOiQ (ORCPT ); Sat, 4 Apr 2020 10:38:16 -0400 Received: from us-smtp-1.mimecast.com ([205.139.110.61]:34265 "EHLO us-smtp-delivery-1.mimecast.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S1726397AbgDDOiP (ORCPT ); Sat, 4 Apr 2020 10:38:15 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1586011095; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=E3BV988DpZ1VkA4WWHvhl1mOj9xBGw7xFZ3+tYvTVds=; b=i0nZFb2v/59MmX69hdE4+RVZcTvJBB3qHwm5JSgGUlPFFN9mm3qreznw4upG7UGxwCbk74 VDLrLGZa1OoFlMSILNVgjuAIf0KyxnKxzBfv2Fn0U/aWifeoDYa3m47Tg+aro7zpunDoAy yvzgbglUEArAfEtDYPl8KUOiD5bfUcE= Received: from mimecast-mx01.redhat.com (mimecast-mx01.redhat.com [209.132.183.4]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-174-T2IZTTFqOt2WcY50aea6BQ-1; Sat, 04 Apr 2020 10:38:10 -0400 X-MC-Unique: T2IZTTFqOt2WcY50aea6BQ-1 Received: from smtp.corp.redhat.com (int-mx01.intmail.prod.int.phx2.redhat.com [10.5.11.11]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id B3BAF18AB2C0; Sat, 4 Apr 2020 14:38:09 +0000 (UTC) Received: from kamzik.brq.redhat.com (unknown [10.40.192.30]) by smtp.corp.redhat.com (Postfix) with ESMTP id C67F69B912; Sat, 4 Apr 2020 14:38:07 +0000 (UTC) From: Andrew Jones To: pbonzini@redhat.com Cc: kvm@vger.kernel.org, kvmarm@lists.cs.columbia.edu, Zenghui Yu , Alexandru Elisei Subject: [PULL kvm-unit-tests 12/39] arm64: timer: Use the proper RDist register name in GICv3 Date: Sat, 4 Apr 2020 16:37:04 +0200 Message-Id: <20200404143731.208138-13-drjones@redhat.com> In-Reply-To: <20200404143731.208138-1-drjones@redhat.com> References: <20200404143731.208138-1-drjones@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.11 Sender: kvm-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: kvm@vger.kernel.org From: Zenghui Yu We're actually going to read GICR_ISACTIVER0 and GICR_ISPENDR0 (in SGI_base frame of the redistribitor) to get the active/pending state of the timer interrupt. Fix this typo. And since they have the same value, there's no functional change. Signed-off-by: Zenghui Yu Reviewed-by: Alexandru Elisei Signed-off-by: Andrew Jones --- arm/timer.c | 4 ++-- lib/arm/asm/gic-v3.h | 4 ++++ 2 files changed, 6 insertions(+), 2 deletions(-) diff --git a/arm/timer.c b/arm/timer.c index 94543f231ba9..10a88f3f1d19 100644 --- a/arm/timer.c +++ b/arm/timer.c @@ -351,8 +351,8 @@ static void test_init(void) gic_icenabler = gicv2_dist_base() + GICD_ICENABLER; break; case 3: - gic_isactiver = gicv3_sgi_base() + GICD_ISACTIVER; - gic_ispendr = gicv3_sgi_base() + GICD_ISPENDR; + gic_isactiver = gicv3_sgi_base() + GICR_ISACTIVER0; + gic_ispendr = gicv3_sgi_base() + GICR_ISPENDR0; gic_isenabler = gicv3_sgi_base() + GICR_ISENABLER0; gic_icenabler = gicv3_sgi_base() + GICR_ICENABLER0; break; diff --git a/lib/arm/asm/gic-v3.h b/lib/arm/asm/gic-v3.h index 0dc838b3ab2d..e2736a12b319 100644 --- a/lib/arm/asm/gic-v3.h +++ b/lib/arm/asm/gic-v3.h @@ -32,6 +32,10 @@ #define GICR_IGROUPR0 GICD_IGROUPR #define GICR_ISENABLER0 GICD_ISENABLER #define GICR_ICENABLER0 GICD_ICENABLER +#define GICR_ISPENDR0 GICD_ISPENDR +#define GICR_ICPENDR0 GICD_ICPENDR +#define GICR_ISACTIVER0 GICD_ISACTIVER +#define GICR_ICACTIVER0 GICD_ICACTIVER #define GICR_IPRIORITYR0 GICD_IPRIORITYR #define ICC_SGI1R_AFFINITY_1_SHIFT 16 From patchwork Sat Apr 4 14:37:05 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Andrew Jones X-Patchwork-Id: 11474327 Return-Path: Received: from mail.kernel.org (pdx-korg-mail-1.web.codeaurora.org [172.30.200.123]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 9CF4B912 for ; Sat, 4 Apr 2020 14:38:21 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id 7C1B92071C for ; Sat, 4 Apr 2020 14:38:21 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (1024-bit key) header.d=redhat.com header.i=@redhat.com header.b="gez8s6Od" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726494AbgDDOiU (ORCPT ); Sat, 4 Apr 2020 10:38:20 -0400 Received: from us-smtp-delivery-1.mimecast.com ([207.211.31.120]:22910 "EHLO us-smtp-1.mimecast.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S1726490AbgDDOiU (ORCPT ); Sat, 4 Apr 2020 10:38:20 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1586011099; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=X/FnkgGUsHKu76b7rfSyf9V2vp8FmKEyZRkIYQEnR7c=; b=gez8s6OdzI565C6GjPp3CXFQGyMzc1IEk4xYdKIviMqnwZfh+tm9BnNtiDu2M582/HRVYM NRqhhbVFuESOuKhYjCpjIKJc4O/yU7cHRWcCko+rHqhsv7BJ32/Yyl7HK2coa8Ttf6w8gE pryVcNiIJXC1drjqQYG04K6ojMXKIV4= Received: from mimecast-mx01.redhat.com (mimecast-mx01.redhat.com [209.132.183.4]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-473-kRr9Vb7zPLuZE7cheQwSxg-1; Sat, 04 Apr 2020 10:38:12 -0400 X-MC-Unique: kRr9Vb7zPLuZE7cheQwSxg-1 Received: from smtp.corp.redhat.com (int-mx01.intmail.prod.int.phx2.redhat.com [10.5.11.11]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id 5C8261005509; Sat, 4 Apr 2020 14:38:11 +0000 (UTC) Received: from kamzik.brq.redhat.com (unknown [10.40.192.30]) by smtp.corp.redhat.com (Postfix) with ESMTP id 142B29B912; Sat, 4 Apr 2020 14:38:09 +0000 (UTC) From: Andrew Jones To: pbonzini@redhat.com Cc: kvm@vger.kernel.org, kvmarm@lists.cs.columbia.edu, Zenghui Yu Subject: [PULL kvm-unit-tests 13/39] arm64: timer: Use existing helpers to access counter/timers Date: Sat, 4 Apr 2020 16:37:05 +0200 Message-Id: <20200404143731.208138-14-drjones@redhat.com> In-Reply-To: <20200404143731.208138-1-drjones@redhat.com> References: <20200404143731.208138-1-drjones@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.11 Sender: kvm-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: kvm@vger.kernel.org From: Zenghui Yu We already have some good helpers to access the counter and timer registers. Use them to avoid open coding the accessors again. Signed-off-by: Zenghui Yu Signed-off-by: Andrew Jones --- arm/timer.c | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/arm/timer.c b/arm/timer.c index 10a88f3f1d19..f5cf775ce50f 100644 --- a/arm/timer.c +++ b/arm/timer.c @@ -331,7 +331,7 @@ static void test_init(void) vtimer_info.irq_flags = fdt32_to_cpu(data[8]); install_exception_handler(EL1H_SYNC, ESR_EL1_EC_UNKNOWN, ptimer_unsupported_handler); - read_sysreg(cntp_ctl_el0); + ptimer_info.read_ctl(); install_exception_handler(EL1H_SYNC, ESR_EL1_EC_UNKNOWN, NULL); if (ptimer_unsupported && !ERRATA(7b6b46311a85)) { @@ -366,15 +366,15 @@ static void print_timer_info(void) { printf("CNTFRQ_EL0 : 0x%016lx\n", read_sysreg(cntfrq_el0)); - if (!ptimer_unsupported){ - printf("CNTPCT_EL0 : 0x%016lx\n", read_sysreg(cntpct_el0)); - printf("CNTP_CTL_EL0 : 0x%016lx\n", read_sysreg(cntp_ctl_el0)); - printf("CNTP_CVAL_EL0: 0x%016lx\n", read_sysreg(cntp_cval_el0)); + if (!ptimer_unsupported) { + printf("CNTPCT_EL0 : 0x%016lx\n", ptimer_info.read_counter()); + printf("CNTP_CTL_EL0 : 0x%016lx\n", ptimer_info.read_ctl()); + printf("CNTP_CVAL_EL0: 0x%016lx\n", ptimer_info.read_cval()); } - printf("CNTVCT_EL0 : 0x%016lx\n", read_sysreg(cntvct_el0)); - printf("CNTV_CTL_EL0 : 0x%016lx\n", read_sysreg(cntv_ctl_el0)); - printf("CNTV_CVAL_EL0: 0x%016lx\n", read_sysreg(cntv_cval_el0)); + printf("CNTVCT_EL0 : 0x%016lx\n", vtimer_info.read_counter()); + printf("CNTV_CTL_EL0 : 0x%016lx\n", vtimer_info.read_ctl()); + printf("CNTV_CVAL_EL0: 0x%016lx\n", vtimer_info.read_cval()); } int main(int argc, char **argv) From patchwork Sat Apr 4 14:37:06 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Andrew Jones X-Patchwork-Id: 11474329 Return-Path: Received: from mail.kernel.org (pdx-korg-mail-1.web.codeaurora.org [172.30.200.123]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id C7F151392 for ; Sat, 4 Apr 2020 14:38:22 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id 9CDDC2070E for ; Sat, 4 Apr 2020 14:38:22 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (1024-bit key) header.d=redhat.com header.i=@redhat.com header.b="GTm5A/6B" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726498AbgDDOiV (ORCPT ); Sat, 4 Apr 2020 10:38:21 -0400 Received: from us-smtp-1.mimecast.com ([207.211.31.81]:37715 "EHLO us-smtp-delivery-1.mimecast.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S1726397AbgDDOiV (ORCPT ); Sat, 4 Apr 2020 10:38:21 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1586011100; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=P+115P3D/2L80AskHNCP5H3SmvSJHffKjc1kigImsFQ=; b=GTm5A/6Bc7kgIrCzqG2grjCt8F+oKSo3Zv1jeYim8gOWlhG7hH66yj309k4KW9E4nxXlJf 0Ht/ThlzHa48HbO85fEq48zzngQaZWUmzCeK5irT16RQdmXWaXO8UsictqDv1J7x+lPR3D +JRwb+c/KvCppq0PjeuVbsrYsQya21k= Received: from mimecast-mx01.redhat.com (mimecast-mx01.redhat.com [209.132.183.4]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-481-5f8OHxPAMyeISq1oruKp0g-1; Sat, 04 Apr 2020 10:38:14 -0400 X-MC-Unique: 5f8OHxPAMyeISq1oruKp0g-1 Received: from smtp.corp.redhat.com (int-mx01.intmail.prod.int.phx2.redhat.com [10.5.11.11]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id 37B928017CE; Sat, 4 Apr 2020 14:38:13 +0000 (UTC) Received: from kamzik.brq.redhat.com (unknown [10.40.192.30]) by smtp.corp.redhat.com (Postfix) with ESMTP id B306C9B912; Sat, 4 Apr 2020 14:38:11 +0000 (UTC) From: Andrew Jones To: pbonzini@redhat.com Cc: kvm@vger.kernel.org, kvmarm@lists.cs.columbia.edu, Zenghui Yu , Alexandru Elisei Subject: [PULL kvm-unit-tests 14/39] arm64: timer: Speed up gic-timer-state check Date: Sat, 4 Apr 2020 16:37:06 +0200 Message-Id: <20200404143731.208138-15-drjones@redhat.com> In-Reply-To: <20200404143731.208138-1-drjones@redhat.com> References: <20200404143731.208138-1-drjones@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.11 Sender: kvm-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: kvm@vger.kernel.org Let's bail out of the wait loop if we see the expected state to save over six seconds of run time. Make sure we wait a bit before reading the registers and double check again after, though, to somewhat mitigate the chance of seeing the expected state by accident. We also take this opportunity to push more IRQ state code to the library. Cc: Zenghui Yu Reviewed-by: Zenghui Yu Tested-by: Zenghui Yu Reviewed-by: Alexandru Elisei Signed-off-by: Andrew Jones --- arm/timer.c | 36 ++++++++++++------------------------ lib/arm/asm/gic.h | 11 ++++++----- lib/arm/gic.c | 45 +++++++++++++++++++++++++++++++++++++++++++++ 3 files changed, 63 insertions(+), 29 deletions(-) diff --git a/arm/timer.c b/arm/timer.c index f5cf775ce50f..44621b4f2967 100644 --- a/arm/timer.c +++ b/arm/timer.c @@ -17,8 +17,6 @@ #define ARCH_TIMER_CTL_IMASK (1 << 1) #define ARCH_TIMER_CTL_ISTATUS (1 << 2) -static void *gic_isactiver; -static void *gic_ispendr; static void *gic_isenabler; static void *gic_icenabler; @@ -183,28 +181,22 @@ static bool timer_pending(struct timer_info *info) (info->read_ctl() & ARCH_TIMER_CTL_ISTATUS); } -static enum gic_state gic_timer_state(struct timer_info *info) +static bool gic_timer_check_state(struct timer_info *info, + enum gic_irq_state expected_state) { - enum gic_state state = GIC_STATE_INACTIVE; int i; - bool pending, active; /* Wait for up to 1s for the GIC to sample the interrupt. */ for (i = 0; i < 10; i++) { - pending = readl(gic_ispendr) & (1 << PPI(info->irq)); - active = readl(gic_isactiver) & (1 << PPI(info->irq)); - if (!active && !pending) - state = GIC_STATE_INACTIVE; - if (pending) - state = GIC_STATE_PENDING; - if (active) - state = GIC_STATE_ACTIVE; - if (active && pending) - state = GIC_STATE_ACTIVE_PENDING; mdelay(100); + if (gic_irq_state(PPI(info->irq)) == expected_state) { + mdelay(100); + if (gic_irq_state(PPI(info->irq)) == expected_state) + return true; + } } - return state; + return false; } static bool test_cval_10msec(struct timer_info *info) @@ -253,11 +245,11 @@ static void test_timer(struct timer_info *info) /* Enable the timer, but schedule it for much later */ info->write_cval(later); info->write_ctl(ARCH_TIMER_CTL_ENABLE); - report(!timer_pending(info) && gic_timer_state(info) == GIC_STATE_INACTIVE, + report(!timer_pending(info) && gic_timer_check_state(info, GIC_IRQ_STATE_INACTIVE), "not pending before"); info->write_cval(now - 1); - report(timer_pending(info) && gic_timer_state(info) == GIC_STATE_PENDING, + report(timer_pending(info) && gic_timer_check_state(info, GIC_IRQ_STATE_PENDING), "interrupt signal pending"); /* Disable the timer again and prepare to take interrupts */ @@ -265,12 +257,12 @@ static void test_timer(struct timer_info *info) info->irq_received = false; set_timer_irq_enabled(info, true); report(!info->irq_received, "no interrupt when timer is disabled"); - report(!timer_pending(info) && gic_timer_state(info) == GIC_STATE_INACTIVE, + report(!timer_pending(info) && gic_timer_check_state(info, GIC_IRQ_STATE_INACTIVE), "interrupt signal no longer pending"); info->write_cval(now - 1); info->write_ctl(ARCH_TIMER_CTL_ENABLE | ARCH_TIMER_CTL_IMASK); - report(timer_pending(info) && gic_timer_state(info) == GIC_STATE_INACTIVE, + report(timer_pending(info) && gic_timer_check_state(info, GIC_IRQ_STATE_INACTIVE), "interrupt signal not pending"); report(test_cval_10msec(info), "latency within 10 ms"); @@ -345,14 +337,10 @@ static void test_init(void) switch (gic_version()) { case 2: - gic_isactiver = gicv2_dist_base() + GICD_ISACTIVER; - gic_ispendr = gicv2_dist_base() + GICD_ISPENDR; gic_isenabler = gicv2_dist_base() + GICD_ISENABLER; gic_icenabler = gicv2_dist_base() + GICD_ICENABLER; break; case 3: - gic_isactiver = gicv3_sgi_base() + GICR_ISACTIVER0; - gic_ispendr = gicv3_sgi_base() + GICR_ISPENDR0; gic_isenabler = gicv3_sgi_base() + GICR_ISENABLER0; gic_icenabler = gicv3_sgi_base() + GICR_ICENABLER0; break; diff --git a/lib/arm/asm/gic.h b/lib/arm/asm/gic.h index a72e0cde4e9c..922cbe95750c 100644 --- a/lib/arm/asm/gic.h +++ b/lib/arm/asm/gic.h @@ -47,11 +47,11 @@ #ifndef __ASSEMBLY__ #include -enum gic_state { - GIC_STATE_INACTIVE, - GIC_STATE_PENDING, - GIC_STATE_ACTIVE, - GIC_STATE_ACTIVE_PENDING, +enum gic_irq_state { + GIC_IRQ_STATE_INACTIVE, + GIC_IRQ_STATE_PENDING, + GIC_IRQ_STATE_ACTIVE, + GIC_IRQ_STATE_ACTIVE_PENDING, }; /* @@ -80,6 +80,7 @@ extern u32 gic_iar_irqnr(u32 iar); extern void gic_write_eoir(u32 irqstat); extern void gic_ipi_send_single(int irq, int cpu); extern void gic_ipi_send_mask(int irq, const cpumask_t *dest); +extern enum gic_irq_state gic_irq_state(int irq); #endif /* !__ASSEMBLY__ */ #endif /* _ASMARM_GIC_H_ */ diff --git a/lib/arm/gic.c b/lib/arm/gic.c index 94301169215c..c3c5f6bc5b0e 100644 --- a/lib/arm/gic.c +++ b/lib/arm/gic.c @@ -146,3 +146,48 @@ void gic_ipi_send_mask(int irq, const cpumask_t *dest) assert(gic_common_ops && gic_common_ops->ipi_send_mask); gic_common_ops->ipi_send_mask(irq, dest); } + +enum gic_irq_state gic_irq_state(int irq) +{ + enum gic_irq_state state; + void *ispendr, *isactiver; + bool pending, active; + int offset, mask; + + assert(gic_common_ops); + assert(irq < 1020); + + switch (gic_version()) { + case 2: + ispendr = gicv2_dist_base() + GICD_ISPENDR; + isactiver = gicv2_dist_base() + GICD_ISACTIVER; + break; + case 3: + if (irq < GIC_NR_PRIVATE_IRQS) { + ispendr = gicv3_sgi_base() + GICR_ISPENDR0; + isactiver = gicv3_sgi_base() + GICR_ISACTIVER0; + } else { + ispendr = gicv3_dist_base() + GICD_ISPENDR; + isactiver = gicv3_dist_base() + GICD_ISACTIVER; + } + break; + default: + assert(0); + } + + offset = irq / 32 * 4; + mask = 1 << (irq % 32); + pending = readl(ispendr + offset) & mask; + active = readl(isactiver + offset) & mask; + + if (!active && !pending) + state = GIC_IRQ_STATE_INACTIVE; + if (pending) + state = GIC_IRQ_STATE_PENDING; + if (active) + state = GIC_IRQ_STATE_ACTIVE; + if (active && pending) + state = GIC_IRQ_STATE_ACTIVE_PENDING; + + return state; +} From patchwork Sat Apr 4 14:37:07 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Andrew Jones X-Patchwork-Id: 11474331 Return-Path: Received: from mail.kernel.org (pdx-korg-mail-1.web.codeaurora.org [172.30.200.123]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id BE5DF1392 for ; Sat, 4 Apr 2020 14:38:23 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id 9DA7820731 for ; Sat, 4 Apr 2020 14:38:23 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (1024-bit key) header.d=redhat.com header.i=@redhat.com header.b="hyYWP9+D" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726509AbgDDOiW (ORCPT ); Sat, 4 Apr 2020 10:38:22 -0400 Received: from us-smtp-delivery-1.mimecast.com ([205.139.110.120]:45724 "EHLO us-smtp-1.mimecast.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S1726487AbgDDOiW (ORCPT ); Sat, 4 Apr 2020 10:38:22 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1586011101; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=L5kvEDWFgukSy2VA0460wSvi1JgL9B6H6p7MZytSzpc=; b=hyYWP9+DCR8/9gfa3BGcjQ5TSeEEBhmYwOvs3zdILzwIXTfRoEguB8oVi6zl8RJxNCqltR CmsqnIbbB7vb5tCjPY/qZnvHecnuxXHq+r/1bH86fMrjPubvDOO17FpZjpuDjt3XAYEIkQ DDEMjq+UI5Ym0zReYC0B8dpWngT5se4= Received: from mimecast-mx01.redhat.com (mimecast-mx01.redhat.com [209.132.183.4]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-344-I4n6z8dCMiyRU_4w9jCd0w-1; Sat, 04 Apr 2020 10:38:19 -0400 X-MC-Unique: I4n6z8dCMiyRU_4w9jCd0w-1 Received: from smtp.corp.redhat.com (int-mx01.intmail.prod.int.phx2.redhat.com [10.5.11.11]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id D53A1800D5C; Sat, 4 Apr 2020 14:38:14 +0000 (UTC) Received: from kamzik.brq.redhat.com (unknown [10.40.192.30]) by smtp.corp.redhat.com (Postfix) with ESMTP id 8BE379B912; Sat, 4 Apr 2020 14:38:13 +0000 (UTC) From: Andrew Jones To: pbonzini@redhat.com Cc: kvm@vger.kernel.org, kvmarm@lists.cs.columbia.edu, Alexandru Elisei Subject: [PULL kvm-unit-tests 15/39] arm64: Provide read/write_sysreg_s Date: Sat, 4 Apr 2020 16:37:07 +0200 Message-Id: <20200404143731.208138-16-drjones@redhat.com> In-Reply-To: <20200404143731.208138-1-drjones@redhat.com> References: <20200404143731.208138-1-drjones@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.11 Sender: kvm-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: kvm@vger.kernel.org Sometimes we need to test access to system registers which are missing assembler mnemonics. Signed-off-by: Andrew Jones Reviewed-by: Alexandru Elisei --- lib/arm64/asm/sysreg.h | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/lib/arm64/asm/sysreg.h b/lib/arm64/asm/sysreg.h index a03830bceb8f..a45eebdfb272 100644 --- a/lib/arm64/asm/sysreg.h +++ b/lib/arm64/asm/sysreg.h @@ -38,6 +38,17 @@ asm volatile("msr " xstr(r) ", %x0" : : "rZ" (__val)); \ } while (0) +#define read_sysreg_s(r) ({ \ + u64 __val; \ + asm volatile("mrs_s %0, " xstr(r) : "=r" (__val)); \ + __val; \ +}) + +#define write_sysreg_s(v, r) do { \ + u64 __val = (u64)v; \ + asm volatile("msr_s " xstr(r) ", %x0" : : "rZ" (__val));\ +} while (0) + asm( " .irp num,0,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20,21,22,23,24,25,26,27,28,29,30\n" " .equ .L__reg_num_x\\num, \\num\n" From patchwork Sat Apr 4 14:37:08 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Andrew Jones X-Patchwork-Id: 11474333 Return-Path: Received: from mail.kernel.org (pdx-korg-mail-1.web.codeaurora.org [172.30.200.123]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 13CC9912 for ; Sat, 4 Apr 2020 14:38:25 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id E648E20731 for ; Sat, 4 Apr 2020 14:38:24 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (1024-bit key) header.d=redhat.com header.i=@redhat.com header.b="aCUlivbY" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726536AbgDDOiY (ORCPT ); Sat, 4 Apr 2020 10:38:24 -0400 Received: from us-smtp-1.mimecast.com ([205.139.110.61]:22287 "EHLO us-smtp-delivery-1.mimecast.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S1726504AbgDDOiX (ORCPT ); Sat, 4 Apr 2020 10:38:23 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1586011102; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=jy3EuHQ8mrgm29Jc3heu5uVEvCyCy6E0d+tEjOyDI0g=; b=aCUlivbYe9ZUKI/X3uillq04DTTK6xA6vhtDqDC0HUV9C5byVrr5vKfke/Aynqb0UETXCv qcJvjrnkVJoPk/9dhJx5j5LRr5q+sgBL2ZQARIeSM4uq8BJt9Y6s5HQ56eB0aQ0+Su6J27 mVSMgb924foFDzMcylD9kLLf3HPuCpg= Received: from mimecast-mx01.redhat.com (mimecast-mx01.redhat.com [209.132.183.4]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-186-iHCQ4S7VPaW9pGzK5X48WQ-1; Sat, 04 Apr 2020 10:38:20 -0400 X-MC-Unique: iHCQ4S7VPaW9pGzK5X48WQ-1 Received: from smtp.corp.redhat.com (int-mx01.intmail.prod.int.phx2.redhat.com [10.5.11.11]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id 2C33F8017F4; Sat, 4 Apr 2020 14:38:19 +0000 (UTC) Received: from kamzik.brq.redhat.com (unknown [10.40.192.30]) by smtp.corp.redhat.com (Postfix) with ESMTP id 36E4A9B912; Sat, 4 Apr 2020 14:38:15 +0000 (UTC) From: Andrew Jones To: pbonzini@redhat.com Cc: kvm@vger.kernel.org, kvmarm@lists.cs.columbia.edu, Eric Auger , Andre Przywara Subject: [PULL kvm-unit-tests 16/39] arm: pmu: Let pmu tests take a sub-test parameter Date: Sat, 4 Apr 2020 16:37:08 +0200 Message-Id: <20200404143731.208138-17-drjones@redhat.com> In-Reply-To: <20200404143731.208138-1-drjones@redhat.com> References: <20200404143731.208138-1-drjones@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.11 Sender: kvm-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: kvm@vger.kernel.org From: Eric Auger As we intend to introduce more PMU tests, let's add a sub-test parameter that will allow to categorize them. Existing tests are in the cycle-counter category. Signed-off-by: Eric Auger Reviewed-by: Andre Przywara Signed-off-by: Andrew Jones --- arm/pmu.c | 25 ++++++++++++++++--------- arm/unittests.cfg | 7 ++++--- 2 files changed, 20 insertions(+), 12 deletions(-) diff --git a/arm/pmu.c b/arm/pmu.c index d5a03a6ff0b3..0122f0a8a8a9 100644 --- a/arm/pmu.c +++ b/arm/pmu.c @@ -287,22 +287,29 @@ int main(int argc, char *argv[]) { int cpi = 0; - if (argc > 1) - cpi = atol(argv[1]); - if (!pmu_probe()) { printf("No PMU found, test skipped...\n"); return report_summary(); } - report_prefix_push("pmu"); + if (argc < 2) + report_abort("no test specified"); - report(check_pmcr(), "Control register"); - report(check_cycles_increase(), - "Monotonically increasing cycle count"); - report(check_cpi(cpi), "Cycle/instruction ratio"); + report_prefix_push("pmu"); - pmccntr64_test(); + if (strcmp(argv[1], "cycle-counter") == 0) { + report_prefix_push(argv[1]); + if (argc > 2) + cpi = atol(argv[2]); + report(check_pmcr(), "Control register"); + report(check_cycles_increase(), + "Monotonically increasing cycle count"); + report(check_cpi(cpi), "Cycle/instruction ratio"); + pmccntr64_test(); + report_prefix_pop(); + } else { + report_abort("Unknown sub-test '%s'", argv[1]); + } return report_summary(); } diff --git a/arm/unittests.cfg b/arm/unittests.cfg index 017958d28ffd..fe6515c6b2dc 100644 --- a/arm/unittests.cfg +++ b/arm/unittests.cfg @@ -61,21 +61,22 @@ file = pci-test.flat groups = pci # Test PMU support -[pmu] +[pmu-cycle-counter] file = pmu.flat groups = pmu +extra_params = -append 'cycle-counter 0' # Test PMU support (TCG) with -icount IPC=1 #[pmu-tcg-icount-1] #file = pmu.flat -#extra_params = -icount 0 -append '1' +#extra_params = -icount 0 -append 'cycle-counter 1' #groups = pmu #accel = tcg # Test PMU support (TCG) with -icount IPC=256 #[pmu-tcg-icount-256] #file = pmu.flat -#extra_params = -icount 8 -append '256' +#extra_params = -icount 8 -append 'cycle-counter 256' #groups = pmu #accel = tcg From patchwork Sat Apr 4 14:37:09 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Andrew Jones X-Patchwork-Id: 11474337 Return-Path: Received: from mail.kernel.org (pdx-korg-mail-1.web.codeaurora.org [172.30.200.123]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id DDCC91392 for ; Sat, 4 Apr 2020 14:38:29 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id BD19220731 for ; Sat, 4 Apr 2020 14:38:29 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (1024-bit key) header.d=redhat.com header.i=@redhat.com header.b="WKi5bu9F" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726487AbgDDOi2 (ORCPT ); Sat, 4 Apr 2020 10:38:28 -0400 Received: from us-smtp-2.mimecast.com ([205.139.110.61]:25039 "EHLO us-smtp-delivery-1.mimecast.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S1726132AbgDDOi1 (ORCPT ); Sat, 4 Apr 2020 10:38:27 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1586011106; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=QVuFrhT8TJhNSCuR94NxSXlIlj1+1lGH/d1K+jA+epw=; b=WKi5bu9F55tGL2gvxmfkM1IC3ui7O85S6SzD7CkfMwFayCB/Drhf3UMDWKn/NEjWRQ3Ufb 8BbW0RSUnYTbwEbgENLEhlosE/RhdB0Zi+8xtWFlvU1d1LnoAVZzsjAzSM0eJndui+3T6l gPhLISqHMLUPkvMbh8Sen/P5zLKgXSs= Received: from mimecast-mx01.redhat.com (mimecast-mx01.redhat.com [209.132.183.4]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-330-lLBibGidP72HqiBnmG9P-w-1; Sat, 04 Apr 2020 10:38:22 -0400 X-MC-Unique: lLBibGidP72HqiBnmG9P-w-1 Received: from smtp.corp.redhat.com (int-mx01.intmail.prod.int.phx2.redhat.com [10.5.11.11]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id 0B54318AB2D4; Sat, 4 Apr 2020 14:38:21 +0000 (UTC) Received: from kamzik.brq.redhat.com (unknown [10.40.192.30]) by smtp.corp.redhat.com (Postfix) with ESMTP id 81CE71147D3; Sat, 4 Apr 2020 14:38:19 +0000 (UTC) From: Andrew Jones To: pbonzini@redhat.com Cc: kvm@vger.kernel.org, kvmarm@lists.cs.columbia.edu, Eric Auger , Peter Maydell Subject: [PULL kvm-unit-tests 17/39] arm: pmu: Don't check PMCR.IMP anymore Date: Sat, 4 Apr 2020 16:37:09 +0200 Message-Id: <20200404143731.208138-18-drjones@redhat.com> In-Reply-To: <20200404143731.208138-1-drjones@redhat.com> References: <20200404143731.208138-1-drjones@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.11 Sender: kvm-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: kvm@vger.kernel.org From: Eric Auger check_pmcr() checks the IMP field is different than 0. However A zero IMP field is permitted by the architecture, meaning the MIDR_EL1 should be looked at instead. This causes TCG to fail this test on '-cpu max' because in that case PMCR.IMP is set equal to MIDR_EL1.Implementer which is 0. So let's remove the check_pmcr() test and just print PMCR info in the pmu_probe() function. Signed-off-by: Eric Auger Reported-by: Peter Maydell Signed-off-by: Andrew Jones --- arm/pmu.c | 39 ++++++++++++++------------------------- 1 file changed, 14 insertions(+), 25 deletions(-) diff --git a/arm/pmu.c b/arm/pmu.c index 0122f0a8a8a9..44f3543cfa49 100644 --- a/arm/pmu.c +++ b/arm/pmu.c @@ -134,29 +134,6 @@ static inline void precise_instrs_loop(int loop, uint32_t pmcr) } #endif -/* - * As a simple sanity check on the PMCR_EL0, ensure the implementer field isn't - * null. Also print out a couple other interesting fields for diagnostic - * purposes. For example, as of fall 2016, QEMU TCG mode doesn't implement - * event counters and therefore reports zero event counters, but hopefully - * support for at least the instructions event will be added in the future and - * the reported number of event counters will become nonzero. - */ -static bool check_pmcr(void) -{ - uint32_t pmcr; - - pmcr = get_pmcr(); - - report_info("PMU implementer/ID code/counters: %#x(\"%c\")/%#x/%d", - (pmcr >> PMU_PMCR_IMP_SHIFT) & PMU_PMCR_IMP_MASK, - ((pmcr >> PMU_PMCR_IMP_SHIFT) & PMU_PMCR_IMP_MASK) ? : ' ', - (pmcr >> PMU_PMCR_ID_SHIFT) & PMU_PMCR_ID_MASK, - (pmcr >> PMU_PMCR_N_SHIFT) & PMU_PMCR_N_MASK); - - return ((pmcr >> PMU_PMCR_IMP_SHIFT) & PMU_PMCR_IMP_MASK) != 0; -} - /* * Ensure that the cycle counter progresses between back-to-back reads. */ @@ -278,9 +255,22 @@ static void pmccntr64_test(void) /* Return FALSE if no PMU found, otherwise return TRUE */ static bool pmu_probe(void) { + uint32_t pmcr; + pmu_version = get_pmu_version(); + if (pmu_version == 0 || pmu_version == 0xf) + return false; + report_info("PMU version: %d", pmu_version); - return pmu_version != 0 && pmu_version != 0xf; + + pmcr = get_pmcr(); + report_info("PMU implementer/ID code/counters: %#x(\"%c\")/%#x/%d", + (pmcr >> PMU_PMCR_IMP_SHIFT) & PMU_PMCR_IMP_MASK, + ((pmcr >> PMU_PMCR_IMP_SHIFT) & PMU_PMCR_IMP_MASK) ? : ' ', + (pmcr >> PMU_PMCR_ID_SHIFT) & PMU_PMCR_ID_MASK, + (pmcr >> PMU_PMCR_N_SHIFT) & PMU_PMCR_N_MASK); + + return true; } int main(int argc, char *argv[]) @@ -301,7 +291,6 @@ int main(int argc, char *argv[]) report_prefix_push(argv[1]); if (argc > 2) cpi = atol(argv[2]); - report(check_pmcr(), "Control register"); report(check_cycles_increase(), "Monotonically increasing cycle count"); report(check_cpi(cpi), "Cycle/instruction ratio"); From patchwork Sat Apr 4 14:37:10 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Andrew Jones X-Patchwork-Id: 11474335 Return-Path: Received: from mail.kernel.org (pdx-korg-mail-1.web.codeaurora.org [172.30.200.123]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 796201392 for ; Sat, 4 Apr 2020 14:38:28 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id 58B742071C for ; Sat, 4 Apr 2020 14:38:28 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (1024-bit key) header.d=redhat.com header.i=@redhat.com header.b="LaclZAmJ" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726521AbgDDOi1 (ORCPT ); Sat, 4 Apr 2020 10:38:27 -0400 Received: from us-smtp-delivery-1.mimecast.com ([207.211.31.120]:29091 "EHLO us-smtp-1.mimecast.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S1726477AbgDDOi1 (ORCPT ); Sat, 4 Apr 2020 10:38:27 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1586011106; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=+rMYicE8IRsGNdwnkciZxtp1jiaYqa5jnjZhjK0amnI=; b=LaclZAmJQ+XpRCTj61PPQkM1VoRkG77qF5MMqiJ3gl+vh+3M2FO0rgkH8GKevrov+pXsAw M+u5DFZk5llttaMBJk7VrKI1keKahKWVPls+2yFmjODGZtgA0am2dsXht9vzRlceqXNqM1 z4jyoONfdmI5zVAoUal/jhmUCFhEhhM= Received: from mimecast-mx01.redhat.com (mimecast-mx01.redhat.com [209.132.183.4]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-51-mdlH_xDpPsam40XFQQCtGg-1; Sat, 04 Apr 2020 10:38:24 -0400 X-MC-Unique: mdlH_xDpPsam40XFQQCtGg-1 Received: from smtp.corp.redhat.com (int-mx01.intmail.prod.int.phx2.redhat.com [10.5.11.11]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id E0957800D4E; Sat, 4 Apr 2020 14:38:22 +0000 (UTC) Received: from kamzik.brq.redhat.com (unknown [10.40.192.30]) by smtp.corp.redhat.com (Postfix) with ESMTP id 62D2A9B912; Sat, 4 Apr 2020 14:38:21 +0000 (UTC) From: Andrew Jones To: pbonzini@redhat.com Cc: kvm@vger.kernel.org, kvmarm@lists.cs.columbia.edu, Eric Auger , Andre Przywara Subject: [PULL kvm-unit-tests 18/39] arm: pmu: Add a pmu struct Date: Sat, 4 Apr 2020 16:37:10 +0200 Message-Id: <20200404143731.208138-19-drjones@redhat.com> In-Reply-To: <20200404143731.208138-1-drjones@redhat.com> References: <20200404143731.208138-1-drjones@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.11 Sender: kvm-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: kvm@vger.kernel.org From: Eric Auger This struct aims at storing information potentially used by all tests such as the pmu version, the read-only part of the PMCR, the number of implemented event counters, ... Signed-off-by: Eric Auger Reviewed-by: Andre Przywara Signed-off-by: Andrew Jones --- arm/pmu.c | 29 +++++++++++++++++++++-------- 1 file changed, 21 insertions(+), 8 deletions(-) diff --git a/arm/pmu.c b/arm/pmu.c index 44f3543cfa49..d827e8221c54 100644 --- a/arm/pmu.c +++ b/arm/pmu.c @@ -33,7 +33,14 @@ #define NR_SAMPLES 10 -static unsigned int pmu_version; +struct pmu { + unsigned int version; + unsigned int nb_implemented_counters; + uint32_t pmcr_ro; +}; + +static struct pmu pmu; + #if defined(__arm__) #define ID_DFR0_PERFMON_SHIFT 24 #define ID_DFR0_PERFMON_MASK 0xf @@ -242,7 +249,7 @@ static bool check_cpi(int cpi) static void pmccntr64_test(void) { #ifdef __arm__ - if (pmu_version == 0x3) { + if (pmu.version == 0x3) { if (ERRATA(9e3f7a296940)) { write_sysreg(0xdead, PMCCNTR64); report(read_sysreg(PMCCNTR64) == 0xdead, "pmccntr64"); @@ -257,18 +264,24 @@ static bool pmu_probe(void) { uint32_t pmcr; - pmu_version = get_pmu_version(); - if (pmu_version == 0 || pmu_version == 0xf) + pmu.version = get_pmu_version(); + if (pmu.version == 0 || pmu.version == 0xf) return false; - report_info("PMU version: %d", pmu_version); + report_info("PMU version: %d", pmu.version); pmcr = get_pmcr(); - report_info("PMU implementer/ID code/counters: %#x(\"%c\")/%#x/%d", + report_info("PMU implementer/ID code: %#x(\"%c\")/%#x", (pmcr >> PMU_PMCR_IMP_SHIFT) & PMU_PMCR_IMP_MASK, ((pmcr >> PMU_PMCR_IMP_SHIFT) & PMU_PMCR_IMP_MASK) ? : ' ', - (pmcr >> PMU_PMCR_ID_SHIFT) & PMU_PMCR_ID_MASK, - (pmcr >> PMU_PMCR_N_SHIFT) & PMU_PMCR_N_MASK); + (pmcr >> PMU_PMCR_ID_SHIFT) & PMU_PMCR_ID_MASK); + + /* store read-only and RES0 fields of the PMCR bottom-half*/ + pmu.pmcr_ro = pmcr & 0xFFFFFF00; + pmu.nb_implemented_counters = + (pmcr >> PMU_PMCR_N_SHIFT) & PMU_PMCR_N_MASK; + report_info("Implements %d event counters", + pmu.nb_implemented_counters); return true; } From patchwork Sat Apr 4 14:37:11 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Andrew Jones X-Patchwork-Id: 11474339 Return-Path: Received: from mail.kernel.org (pdx-korg-mail-1.web.codeaurora.org [172.30.200.123]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 1773E912 for ; Sat, 4 Apr 2020 14:38:31 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id E981D206F5 for ; Sat, 4 Apr 2020 14:38:30 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (1024-bit key) header.d=redhat.com header.i=@redhat.com header.b="Br/A3fjo" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726504AbgDDOia (ORCPT ); Sat, 4 Apr 2020 10:38:30 -0400 Received: from us-smtp-2.mimecast.com ([207.211.31.81]:39317 "EHLO us-smtp-delivery-1.mimecast.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S1726545AbgDDOi3 (ORCPT ); Sat, 4 Apr 2020 10:38:29 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1586011108; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=lyqMAw35dUF+KDOL8FBfb3mBbPWhVkrg2r1sN+m0xPE=; b=Br/A3fjoT00zjviAkrTfKRxVa531kvnZ6iulH2X7NwKMG6BxbvEAxHF21SqpTdQcGyi9zv vYbx2XAMmg5AfiNVyKFCNNakO4f3ESey2MENg557Ok6tnmgY1TnqPB9hxetqYLMGVLjDYD GNDtjObnvt5pihp73cLu9yDaungRwbs= Received: from mimecast-mx01.redhat.com (mimecast-mx01.redhat.com [209.132.183.4]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-29-ax1i26pbNqeJmBXvx3RGdw-1; Sat, 04 Apr 2020 10:38:26 -0400 X-MC-Unique: ax1i26pbNqeJmBXvx3RGdw-1 Received: from smtp.corp.redhat.com (int-mx01.intmail.prod.int.phx2.redhat.com [10.5.11.11]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id E2B998017CE; Sat, 4 Apr 2020 14:38:24 +0000 (UTC) Received: from kamzik.brq.redhat.com (unknown [10.40.192.30]) by smtp.corp.redhat.com (Postfix) with ESMTP id 41F2E114811; Sat, 4 Apr 2020 14:38:23 +0000 (UTC) From: Andrew Jones To: pbonzini@redhat.com Cc: kvm@vger.kernel.org, kvmarm@lists.cs.columbia.edu, Eric Auger Subject: [PULL kvm-unit-tests 19/39] arm: pmu: Introduce defines for PMU versions Date: Sat, 4 Apr 2020 16:37:11 +0200 Message-Id: <20200404143731.208138-20-drjones@redhat.com> In-Reply-To: <20200404143731.208138-1-drjones@redhat.com> References: <20200404143731.208138-1-drjones@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.11 Sender: kvm-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: kvm@vger.kernel.org From: Eric Auger Introduce some defines encoding the different PMU versions. v3 is encoded differently in 32 and 64 bits. Signed-off-by: Eric Auger Signed-off-by: Andrew Jones --- arm/pmu.c | 26 +++++++++++++++++++++----- 1 file changed, 21 insertions(+), 5 deletions(-) diff --git a/arm/pmu.c b/arm/pmu.c index d827e8221c54..a04588aacf49 100644 --- a/arm/pmu.c +++ b/arm/pmu.c @@ -45,6 +45,15 @@ static struct pmu pmu; #define ID_DFR0_PERFMON_SHIFT 24 #define ID_DFR0_PERFMON_MASK 0xf +#define ID_DFR0_PMU_NOTIMPL 0b0000 +#define ID_DFR0_PMU_V1 0b0001 +#define ID_DFR0_PMU_V2 0b0010 +#define ID_DFR0_PMU_V3 0b0011 +#define ID_DFR0_PMU_V3_8_1 0b0100 +#define ID_DFR0_PMU_V3_8_4 0b0101 +#define ID_DFR0_PMU_V3_8_5 0b0110 +#define ID_DFR0_PMU_IMPDEF 0b1111 + #define PMCR __ACCESS_CP15(c9, 0, c12, 0) #define ID_DFR0 __ACCESS_CP15(c0, 0, c1, 2) #define PMSELR __ACCESS_CP15(c9, 0, c12, 5) @@ -105,6 +114,13 @@ static inline void precise_instrs_loop(int loop, uint32_t pmcr) #define ID_AA64DFR0_PERFMON_SHIFT 8 #define ID_AA64DFR0_PERFMON_MASK 0xf +#define ID_DFR0_PMU_NOTIMPL 0b0000 +#define ID_DFR0_PMU_V3 0b0001 +#define ID_DFR0_PMU_V3_8_1 0b0100 +#define ID_DFR0_PMU_V3_8_4 0b0101 +#define ID_DFR0_PMU_V3_8_5 0b0110 +#define ID_DFR0_PMU_IMPDEF 0b1111 + static inline uint32_t get_id_aa64dfr0(void) { return read_sysreg(id_aa64dfr0_el1); } static inline uint32_t get_pmcr(void) { return read_sysreg(pmcr_el0); } static inline void set_pmcr(uint32_t v) { write_sysreg(v, pmcr_el0); } @@ -116,7 +132,7 @@ static inline void set_pmccfiltr(uint32_t v) { write_sysreg(v, pmccfiltr_el0); } static inline uint8_t get_pmu_version(void) { uint8_t ver = (get_id_aa64dfr0() >> ID_AA64DFR0_PERFMON_SHIFT) & ID_AA64DFR0_PERFMON_MASK; - return ver == 1 ? 3 : ver; + return ver; } /* @@ -249,7 +265,7 @@ static bool check_cpi(int cpi) static void pmccntr64_test(void) { #ifdef __arm__ - if (pmu.version == 0x3) { + if (pmu.version == ID_DFR0_PMU_V3) { if (ERRATA(9e3f7a296940)) { write_sysreg(0xdead, PMCCNTR64); report(read_sysreg(PMCCNTR64) == 0xdead, "pmccntr64"); @@ -262,13 +278,13 @@ static void pmccntr64_test(void) /* Return FALSE if no PMU found, otherwise return TRUE */ static bool pmu_probe(void) { - uint32_t pmcr; + uint32_t pmcr = get_pmcr(); pmu.version = get_pmu_version(); - if (pmu.version == 0 || pmu.version == 0xf) + if (pmu.version == ID_DFR0_PMU_NOTIMPL || pmu.version == ID_DFR0_PMU_IMPDEF) return false; - report_info("PMU version: %d", pmu.version); + report_info("PMU version: 0x%x", pmu.version); pmcr = get_pmcr(); report_info("PMU implementer/ID code: %#x(\"%c\")/%#x", From patchwork Sat Apr 4 14:37:12 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Andrew Jones X-Patchwork-Id: 11474341 Return-Path: Received: from mail.kernel.org (pdx-korg-mail-1.web.codeaurora.org [172.30.200.123]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id AD8081392 for ; Sat, 4 Apr 2020 14:38:34 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id 8D20D2070E for ; Sat, 4 Apr 2020 14:38:34 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (1024-bit key) header.d=redhat.com header.i=@redhat.com header.b="glfqhbDs" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726551AbgDDOid (ORCPT ); Sat, 4 Apr 2020 10:38:33 -0400 Received: from us-smtp-delivery-1.mimecast.com ([207.211.31.120]:57267 "EHLO us-smtp-1.mimecast.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S1726132AbgDDOid (ORCPT ); Sat, 4 Apr 2020 10:38:33 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1586011112; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=RWDM51GkM0t8MXuYhUbEiZuQwyw2mO/f7NviN5vgA2o=; b=glfqhbDsEKXeJ40jhM/grGpnhSH5gkEzpUWIC+RJoUnr4Tl3CbR37ojsIb6B5tAB3dkXUL vL3UWzxu3orDYr8eQvbi5Vqijn7CZLvDS4eRs7jAq52TwlVAda5z3JWBEs0qcqstSU9NU4 MoKsZBZUgSTMQJWAsCBfNg1IPQpMNyI= Received: from mimecast-mx01.redhat.com (mimecast-mx01.redhat.com [209.132.183.4]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-323-AwdJUGSqOIm9ja5PyfIVbg-1; Sat, 04 Apr 2020 10:38:28 -0400 X-MC-Unique: AwdJUGSqOIm9ja5PyfIVbg-1 Received: from smtp.corp.redhat.com (int-mx01.intmail.prod.int.phx2.redhat.com [10.5.11.11]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id 4A324107ACC7; Sat, 4 Apr 2020 14:38:27 +0000 (UTC) Received: from kamzik.brq.redhat.com (unknown [10.40.192.30]) by smtp.corp.redhat.com (Postfix) with ESMTP id 6410C9B912; Sat, 4 Apr 2020 14:38:25 +0000 (UTC) From: Andrew Jones To: pbonzini@redhat.com Cc: kvm@vger.kernel.org, kvmarm@lists.cs.columbia.edu, Eric Auger Subject: [PULL kvm-unit-tests 20/39] arm: pmu: Check Required Event Support Date: Sat, 4 Apr 2020 16:37:12 +0200 Message-Id: <20200404143731.208138-21-drjones@redhat.com> In-Reply-To: <20200404143731.208138-1-drjones@redhat.com> References: <20200404143731.208138-1-drjones@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.11 Sender: kvm-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: kvm@vger.kernel.org From: Eric Auger If event counters are implemented check the common events required by the PMUv3 are implemented. Some are unconditionally required (SW_INCR, CPU_CYCLES, either INST_RETIRED or INST_SPEC). Some others only are required if the implementation implements some other features. Check those wich are unconditionally required. This test currently fails on TCG as neither INST_RETIRED or INST_SPEC are supported. Signed-off-by: Eric Auger Signed-off-by: Andrew Jones --- arm/pmu.c | 77 +++++++++++++++++++++++++++++++++++++++++++++++ arm/unittests.cfg | 6 ++++ lib/bitops.h | 3 ++ 3 files changed, 86 insertions(+) diff --git a/arm/pmu.c b/arm/pmu.c index a04588aacf49..8c49e50a6b4a 100644 --- a/arm/pmu.c +++ b/arm/pmu.c @@ -18,6 +18,7 @@ #include "asm/barrier.h" #include "asm/sysreg.h" #include "asm/processor.h" +#include #define PMU_PMCR_E (1 << 0) #define PMU_PMCR_C (1 << 2) @@ -33,6 +34,19 @@ #define NR_SAMPLES 10 +/* Some PMU events */ +#define SW_INCR 0x0 +#define INST_RETIRED 0x8 +#define CPU_CYCLES 0x11 +#define INST_PREC 0x1B +#define STALL_FRONTEND 0x23 +#define STALL_BACKEND 0x24 + +#define COMMON_EVENTS_LOW 0x0 +#define COMMON_EVENTS_HIGH 0x3F +#define EXT_COMMON_EVENTS_LOW 0x4000 +#define EXT_COMMON_EVENTS_HIGH 0x403F + struct pmu { unsigned int version; unsigned int nb_implemented_counters; @@ -110,6 +124,10 @@ static inline void precise_instrs_loop(int loop, uint32_t pmcr) : [pmcr] "r" (pmcr), [z] "r" (0) : "cc"); } + +/* event counter tests only implemented for aarch64 */ +static void test_event_introspection(void) {} + #elif defined(__aarch64__) #define ID_AA64DFR0_PERFMON_SHIFT 8 #define ID_AA64DFR0_PERFMON_MASK 0xf @@ -155,6 +173,61 @@ static inline void precise_instrs_loop(int loop, uint32_t pmcr) : [pmcr] "r" (pmcr) : "cc"); } + +#define PMCEID1_EL0 sys_reg(3, 3, 9, 12, 7) + +static bool is_event_supported(uint32_t n, bool warn) +{ + uint64_t pmceid0 = read_sysreg(pmceid0_el0); + uint64_t pmceid1 = read_sysreg_s(PMCEID1_EL0); + bool supported; + uint64_t reg; + + /* + * The low 32-bits of PMCEID0/1 respectively describe + * event support for events 0-31/32-63. Their High + * 32-bits describe support for extended events + * starting at 0x4000, using the same split. + */ + assert((n >= COMMON_EVENTS_LOW && n <= COMMON_EVENTS_HIGH) || + (n >= EXT_COMMON_EVENTS_LOW && n <= EXT_COMMON_EVENTS_HIGH)); + + if (n <= COMMON_EVENTS_HIGH) + reg = lower_32_bits(pmceid0) | ((u64)lower_32_bits(pmceid1) << 32); + else + reg = upper_32_bits(pmceid0) | ((u64)upper_32_bits(pmceid1) << 32); + + supported = reg & (1UL << (n & 0x3F)); + + if (!supported && warn) + report_info("event 0x%x is not supported", n); + return supported; +} + +static void test_event_introspection(void) +{ + bool required_events; + + if (!pmu.nb_implemented_counters) { + report_skip("No event counter, skip ..."); + return; + } + + /* PMUv3 requires an implementation includes some common events */ + required_events = is_event_supported(SW_INCR, true) && + is_event_supported(CPU_CYCLES, true) && + (is_event_supported(INST_RETIRED, true) || + is_event_supported(INST_PREC, true)); + + if (pmu.version >= ID_DFR0_PMU_V3_8_1) { + required_events = required_events && + is_event_supported(STALL_FRONTEND, true) && + is_event_supported(STALL_BACKEND, true); + } + + report(required_events, "Check required events are implemented"); +} + #endif /* @@ -325,6 +398,10 @@ int main(int argc, char *argv[]) report(check_cpi(cpi), "Cycle/instruction ratio"); pmccntr64_test(); report_prefix_pop(); + } else if (strcmp(argv[1], "pmu-event-introspection") == 0) { + report_prefix_push(argv[1]); + test_event_introspection(); + report_prefix_pop(); } else { report_abort("Unknown sub-test '%s'", argv[1]); } diff --git a/arm/unittests.cfg b/arm/unittests.cfg index fe6515c6b2dc..f993548b163c 100644 --- a/arm/unittests.cfg +++ b/arm/unittests.cfg @@ -66,6 +66,12 @@ file = pmu.flat groups = pmu extra_params = -append 'cycle-counter 0' +[pmu-event-introspection] +file = pmu.flat +groups = pmu +arch = arm64 +extra_params = -append 'pmu-event-introspection' + # Test PMU support (TCG) with -icount IPC=1 #[pmu-tcg-icount-1] #file = pmu.flat diff --git a/lib/bitops.h b/lib/bitops.h index 636064c0fa85..b310a227335f 100644 --- a/lib/bitops.h +++ b/lib/bitops.h @@ -33,6 +33,9 @@ #define GENMASK_ULL(h, l) \ (((~0ULL) << (l)) & (~0ULL >> (BITS_PER_LONG_LONG - 1 - (h)))) +#define upper_32_bits(n) ((u32)(((n) >> 16) >> 16)) +#define lower_32_bits(n) ((u32)(n)) + #ifndef HAVE_BUILTIN_FLS static inline unsigned long fls(unsigned long word) { From patchwork Sat Apr 4 14:37:13 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Andrew Jones X-Patchwork-Id: 11474351 Return-Path: Received: from mail.kernel.org (pdx-korg-mail-1.web.codeaurora.org [172.30.200.123]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 6E64E1392 for ; Sat, 4 Apr 2020 14:38:49 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id 2FEA520738 for ; Sat, 4 Apr 2020 14:38:49 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (1024-bit key) header.d=redhat.com header.i=@redhat.com header.b="Gi6agrfG" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726632AbgDDOis (ORCPT ); Sat, 4 Apr 2020 10:38:48 -0400 Received: from us-smtp-1.mimecast.com ([205.139.110.61]:26242 "EHLO us-smtp-delivery-1.mimecast.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S1726608AbgDDOir (ORCPT ); Sat, 4 Apr 2020 10:38:47 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1586011126; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=RwdieKh1dr7iXu/FLP8bvnQHFPuBgqHFiUXEjCUomEw=; b=Gi6agrfGZVo5wkFYiRtP2AFOJ2Ft38DdrY0lUxK278kXxCT819yQnuf3pqE3wo50Ha0s/u WJGlwLGSPSDAVJR4LvPL/X9BlbWSXCTMMpnIMo17lSySjXO1/usdIXR1dBu1QC5+2Qk9qv oOFWC5xHPjrTMnChQtbvhDKQdelLCjE= Received: from mimecast-mx01.redhat.com (mimecast-mx01.redhat.com [209.132.183.4]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-336-LChd9kl3P92hbz1EbqGNbA-1; Sat, 04 Apr 2020 10:38:30 -0400 X-MC-Unique: LChd9kl3P92hbz1EbqGNbA-1 Received: from smtp.corp.redhat.com (int-mx01.intmail.prod.int.phx2.redhat.com [10.5.11.11]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id D0C03100550D; Sat, 4 Apr 2020 14:38:29 +0000 (UTC) Received: from kamzik.brq.redhat.com (unknown [10.40.192.30]) by smtp.corp.redhat.com (Postfix) with ESMTP id C07299B912; Sat, 4 Apr 2020 14:38:27 +0000 (UTC) From: Andrew Jones To: pbonzini@redhat.com Cc: kvm@vger.kernel.org, kvmarm@lists.cs.columbia.edu, Eric Auger , Andre Przywara Subject: [PULL kvm-unit-tests 21/39] arm: pmu: Basic event counter Tests Date: Sat, 4 Apr 2020 16:37:13 +0200 Message-Id: <20200404143731.208138-22-drjones@redhat.com> In-Reply-To: <20200404143731.208138-1-drjones@redhat.com> References: <20200404143731.208138-1-drjones@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.11 Sender: kvm-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: kvm@vger.kernel.org From: Eric Auger Adds the following tests: - event-counter-config: test event counter configuration - basic-event-count: - programs counters #0 and #1 to count 2 required events (resp. CPU_CYCLES and INST_RETIRED). Counter #0 is preset to a value close enough to the 32b overflow limit so that we check the overflow bit is set after the execution of the asm loop. - mem-access: counts MEM_ACCESS event on counters #0 and #1 with and without 32-bit overflow. Signed-off-by: Eric Auger Reviewed-by: Andre Przywara Signed-off-by: Andrew Jones --- arm/pmu.c | 247 +++++++++++++++++++++++++++++++++++++++++ arm/unittests.cfg | 18 +++ lib/arm64/asm/sysreg.h | 6 + 3 files changed, 271 insertions(+) diff --git a/arm/pmu.c b/arm/pmu.c index 8c49e50a6b4a..4a605c18064f 100644 --- a/arm/pmu.c +++ b/arm/pmu.c @@ -19,9 +19,14 @@ #include "asm/sysreg.h" #include "asm/processor.h" #include +#include #define PMU_PMCR_E (1 << 0) +#define PMU_PMCR_P (1 << 1) #define PMU_PMCR_C (1 << 2) +#define PMU_PMCR_D (1 << 3) +#define PMU_PMCR_X (1 << 4) +#define PMU_PMCR_DP (1 << 5) #define PMU_PMCR_LC (1 << 6) #define PMU_PMCR_N_SHIFT 11 #define PMU_PMCR_N_MASK 0x1f @@ -38,6 +43,7 @@ #define SW_INCR 0x0 #define INST_RETIRED 0x8 #define CPU_CYCLES 0x11 +#define MEM_ACCESS 0x13 #define INST_PREC 0x1B #define STALL_FRONTEND 0x23 #define STALL_BACKEND 0x24 @@ -47,6 +53,10 @@ #define EXT_COMMON_EVENTS_LOW 0x4000 #define EXT_COMMON_EVENTS_HIGH 0x403F +#define ALL_SET 0xFFFFFFFF +#define ALL_CLEAR 0x0 +#define PRE_OVERFLOW 0xFFFFFFF0 + struct pmu { unsigned int version; unsigned int nb_implemented_counters; @@ -127,6 +137,9 @@ static inline void precise_instrs_loop(int loop, uint32_t pmcr) /* event counter tests only implemented for aarch64 */ static void test_event_introspection(void) {} +static void test_event_counter_config(void) {} +static void test_basic_event_count(void) {} +static void test_mem_access(void) {} #elif defined(__aarch64__) #define ID_AA64DFR0_PERFMON_SHIFT 8 @@ -175,6 +188,11 @@ static inline void precise_instrs_loop(int loop, uint32_t pmcr) } #define PMCEID1_EL0 sys_reg(3, 3, 9, 12, 7) +#define PMCNTENSET_EL0 sys_reg(3, 3, 9, 12, 1) +#define PMCNTENCLR_EL0 sys_reg(3, 3, 9, 12, 2) + +#define PMEVTYPER_EXCLUDE_EL1 BIT(31) +#define PMEVTYPER_EXCLUDE_EL0 BIT(30) static bool is_event_supported(uint32_t n, bool warn) { @@ -228,6 +246,223 @@ static void test_event_introspection(void) report(required_events, "Check required events are implemented"); } +/* + * Extra instructions inserted by the compiler would be difficult to compensate + * for, so hand assemble everything between, and including, the PMCR accesses + * to start and stop counting. isb instructions are inserted to make sure + * pmccntr read after this function returns the exact instructions executed + * in the controlled block. Loads @loop times the data at @address into x9. + */ +static void mem_access_loop(void *addr, int loop, uint32_t pmcr) +{ +asm volatile( + " msr pmcr_el0, %[pmcr]\n" + " isb\n" + " mov x10, %[loop]\n" + "1: sub x10, x10, #1\n" + " ldr x9, [%[addr]]\n" + " cmp x10, #0x0\n" + " b.gt 1b\n" + " msr pmcr_el0, xzr\n" + " isb\n" + : + : [addr] "r" (addr), [pmcr] "r" (pmcr), [loop] "r" (loop) + : "x9", "x10", "cc"); +} + +static void pmu_reset(void) +{ + /* reset all counters, counting disabled at PMCR level*/ + set_pmcr(pmu.pmcr_ro | PMU_PMCR_LC | PMU_PMCR_C | PMU_PMCR_P); + /* Disable all counters */ + write_sysreg_s(ALL_SET, PMCNTENCLR_EL0); + /* clear overflow reg */ + write_sysreg(ALL_SET, pmovsclr_el0); + /* disable overflow interrupts on all counters */ + write_sysreg(ALL_SET, pmintenclr_el1); + isb(); +} + +static void test_event_counter_config(void) +{ + int i; + + if (!pmu.nb_implemented_counters) { + report_skip("No event counter, skip ..."); + return; + } + + pmu_reset(); + + /* + * Test setting through PMESELR/PMXEVTYPER and PMEVTYPERn read, + * select counter 0 + */ + write_sysreg(1, PMSELR_EL0); + /* program this counter to count unsupported event */ + write_sysreg(0xEA, PMXEVTYPER_EL0); + write_sysreg(0xdeadbeef, PMXEVCNTR_EL0); + report((read_regn_el0(pmevtyper, 1) & 0xFFF) == 0xEA, + "PMESELR/PMXEVTYPER/PMEVTYPERn"); + report((read_regn_el0(pmevcntr, 1) == 0xdeadbeef), + "PMESELR/PMXEVCNTR/PMEVCNTRn"); + + /* try to configure an unsupported event within the range [0x0, 0x3F] */ + for (i = 0; i <= 0x3F; i++) { + if (!is_event_supported(i, false)) + break; + } + if (i > 0x3F) { + report_skip("pmevtyper: all events within [0x0, 0x3F] are supported"); + return; + } + + /* select counter 0 */ + write_sysreg(0, PMSELR_EL0); + /* program this counter to count unsupported event */ + write_sysreg(i, PMXEVCNTR_EL0); + /* read the counter value */ + read_sysreg(PMXEVCNTR_EL0); + report(read_sysreg(PMXEVCNTR_EL0) == i, + "read of a counter programmed with unsupported event"); +} + +static bool satisfy_prerequisites(uint32_t *events, unsigned int nb_events) +{ + int i; + + if (pmu.nb_implemented_counters < nb_events) { + report_skip("Skip test as number of counters is too small (%d)", + pmu.nb_implemented_counters); + return false; + } + + for (i = 0; i < nb_events; i++) { + if (!is_event_supported(events[i], false)) { + report_skip("Skip test as event 0x%x is not supported", + events[i]); + return false; + } + } + return true; +} + +static void test_basic_event_count(void) +{ + uint32_t implemented_counter_mask, non_implemented_counter_mask; + uint32_t counter_mask; + uint32_t events[] = {CPU_CYCLES, INST_RETIRED}; + + if (!satisfy_prerequisites(events, ARRAY_SIZE(events))) + return; + + implemented_counter_mask = BIT(pmu.nb_implemented_counters) - 1; + non_implemented_counter_mask = ~(BIT(31) | implemented_counter_mask); + counter_mask = implemented_counter_mask | non_implemented_counter_mask; + + write_regn_el0(pmevtyper, 0, CPU_CYCLES | PMEVTYPER_EXCLUDE_EL0); + write_regn_el0(pmevtyper, 1, INST_RETIRED | PMEVTYPER_EXCLUDE_EL0); + + /* disable all counters */ + write_sysreg_s(ALL_SET, PMCNTENCLR_EL0); + report(!read_sysreg_s(PMCNTENCLR_EL0) && !read_sysreg_s(PMCNTENSET_EL0), + "pmcntenclr: disable all counters"); + + /* + * clear cycle and all event counters and allow counter enablement + * through PMCNTENSET. LC is RES1. + */ + set_pmcr(pmu.pmcr_ro | PMU_PMCR_LC | PMU_PMCR_C | PMU_PMCR_P); + isb(); + report(get_pmcr() == (pmu.pmcr_ro | PMU_PMCR_LC), "pmcr: reset counters"); + + /* Preset counter #0 to pre overflow value to trigger an overflow */ + write_regn_el0(pmevcntr, 0, PRE_OVERFLOW); + report(read_regn_el0(pmevcntr, 0) == PRE_OVERFLOW, + "counter #0 preset to pre-overflow value"); + report(!read_regn_el0(pmevcntr, 1), "counter #1 is 0"); + + /* + * Enable all implemented counters and also attempt to enable + * not supported counters. Counting still is disabled by !PMCR.E + */ + write_sysreg_s(counter_mask, PMCNTENSET_EL0); + + /* check only those implemented are enabled */ + report((read_sysreg_s(PMCNTENSET_EL0) == read_sysreg_s(PMCNTENCLR_EL0)) && + (read_sysreg_s(PMCNTENSET_EL0) == implemented_counter_mask), + "pmcntenset: enabled implemented_counters"); + + /* Disable all counters but counters #0 and #1 */ + write_sysreg_s(~0x3, PMCNTENCLR_EL0); + report((read_sysreg_s(PMCNTENSET_EL0) == read_sysreg_s(PMCNTENCLR_EL0)) && + (read_sysreg_s(PMCNTENSET_EL0) == 0x3), + "pmcntenset: just enabled #0 and #1"); + + /* clear overflow register */ + write_sysreg(ALL_SET, pmovsclr_el0); + report(!read_sysreg(pmovsclr_el0), "check overflow reg is 0"); + + /* disable overflow interrupts on all counters*/ + write_sysreg(ALL_SET, pmintenclr_el1); + report(!read_sysreg(pmintenclr_el1), + "pmintenclr_el1=0, all interrupts disabled"); + + /* enable overflow interrupts on all event counters */ + write_sysreg(implemented_counter_mask | non_implemented_counter_mask, + pmintenset_el1); + report(read_sysreg(pmintenset_el1) == implemented_counter_mask, + "overflow interrupts enabled on all implemented counters"); + + /* Set PMCR.E, execute asm code and unset PMCR.E */ + precise_instrs_loop(20, pmu.pmcr_ro | PMU_PMCR_E); + + report_info("counter #0 is 0x%lx (CPU_CYCLES)", + read_regn_el0(pmevcntr, 0)); + report_info("counter #1 is 0x%lx (INST_RETIRED)", + read_regn_el0(pmevcntr, 1)); + + report_info("overflow reg = 0x%lx", read_sysreg(pmovsclr_el0)); + report(read_sysreg(pmovsclr_el0) & 0x1, + "check overflow happened on #0 only"); +} + +static void test_mem_access(void) +{ + void *addr = malloc(PAGE_SIZE); + uint32_t events[] = {MEM_ACCESS, MEM_ACCESS}; + + if (!satisfy_prerequisites(events, ARRAY_SIZE(events))) + return; + + pmu_reset(); + + write_regn_el0(pmevtyper, 0, MEM_ACCESS | PMEVTYPER_EXCLUDE_EL0); + write_regn_el0(pmevtyper, 1, MEM_ACCESS | PMEVTYPER_EXCLUDE_EL0); + write_sysreg_s(0x3, PMCNTENSET_EL0); + isb(); + mem_access_loop(addr, 20, pmu.pmcr_ro | PMU_PMCR_E); + report_info("counter #0 is %ld (MEM_ACCESS)", read_regn_el0(pmevcntr, 0)); + report_info("counter #1 is %ld (MEM_ACCESS)", read_regn_el0(pmevcntr, 1)); + /* We may measure more than 20 mem access depending on the core */ + report((read_regn_el0(pmevcntr, 0) == read_regn_el0(pmevcntr, 1)) && + (read_regn_el0(pmevcntr, 0) >= 20) && !read_sysreg(pmovsclr_el0), + "Ran 20 mem accesses"); + + pmu_reset(); + + write_regn_el0(pmevcntr, 0, PRE_OVERFLOW); + write_regn_el0(pmevcntr, 1, PRE_OVERFLOW); + write_sysreg_s(0x3, PMCNTENSET_EL0); + isb(); + mem_access_loop(addr, 20, pmu.pmcr_ro | PMU_PMCR_E); + report(read_sysreg(pmovsclr_el0) == 0x3, + "Ran 20 mem accesses with expected overflows on both counters"); + report_info("cnt#0 = %ld cnt#1=%ld overflow=0x%lx", + read_regn_el0(pmevcntr, 0), read_regn_el0(pmevcntr, 1), + read_sysreg(pmovsclr_el0)); +} + #endif /* @@ -402,6 +637,18 @@ int main(int argc, char *argv[]) report_prefix_push(argv[1]); test_event_introspection(); report_prefix_pop(); + } else if (strcmp(argv[1], "pmu-event-counter-config") == 0) { + report_prefix_push(argv[1]); + test_event_counter_config(); + report_prefix_pop(); + } else if (strcmp(argv[1], "pmu-basic-event-count") == 0) { + report_prefix_push(argv[1]); + test_basic_event_count(); + report_prefix_pop(); + } else if (strcmp(argv[1], "pmu-mem-access") == 0) { + report_prefix_push(argv[1]); + test_mem_access(); + report_prefix_pop(); } else { report_abort("Unknown sub-test '%s'", argv[1]); } diff --git a/arm/unittests.cfg b/arm/unittests.cfg index f993548b163c..32ab8c6fe06a 100644 --- a/arm/unittests.cfg +++ b/arm/unittests.cfg @@ -72,6 +72,24 @@ groups = pmu arch = arm64 extra_params = -append 'pmu-event-introspection' +[pmu-event-counter-config] +file = pmu.flat +groups = pmu +arch = arm64 +extra_params = -append 'pmu-event-counter-config' + +[pmu-basic-event-count] +file = pmu.flat +groups = pmu +arch = arm64 +extra_params = -append 'pmu-basic-event-count' + +[pmu-mem-access] +file = pmu.flat +groups = pmu +arch = arm64 +extra_params = -append 'pmu-mem-access' + # Test PMU support (TCG) with -icount IPC=1 #[pmu-tcg-icount-1] #file = pmu.flat diff --git a/lib/arm64/asm/sysreg.h b/lib/arm64/asm/sysreg.h index a45eebdfb272..378bf7ebb3b5 100644 --- a/lib/arm64/asm/sysreg.h +++ b/lib/arm64/asm/sysreg.h @@ -49,6 +49,12 @@ asm volatile("msr_s " xstr(r) ", %x0" : : "rZ" (__val));\ } while (0) +#define write_regn_el0(__reg, __n, __val) \ + write_sysreg((__val), __reg ## __n ## _el0) + +#define read_regn_el0(__reg, __n) \ + read_sysreg(__reg ## __n ## _el0) + asm( " .irp num,0,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20,21,22,23,24,25,26,27,28,29,30\n" " .equ .L__reg_num_x\\num, \\num\n" From patchwork Sat Apr 4 14:37:14 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Andrew Jones X-Patchwork-Id: 11474343 Return-Path: Received: from mail.kernel.org (pdx-korg-mail-1.web.codeaurora.org [172.30.200.123]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 5DDCF1392 for ; Sat, 4 Apr 2020 14:38:37 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id 3CDBF2070E for ; Sat, 4 Apr 2020 14:38:37 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (1024-bit key) header.d=redhat.com header.i=@redhat.com header.b="LlmxFPxT" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726569AbgDDOig (ORCPT ); Sat, 4 Apr 2020 10:38:36 -0400 Received: from us-smtp-1.mimecast.com ([205.139.110.61]:48318 "EHLO us-smtp-delivery-1.mimecast.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S1726555AbgDDOig (ORCPT ); Sat, 4 Apr 2020 10:38:36 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1586011115; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=MvxU7Ss59FG5Zx9PkSdNwBKbxalmhsB13IBVxvATAlI=; b=LlmxFPxTN27gISNgulFvkunrXhf7bL99jJeTO3gM+d7GhuGRLngz9tPxpmfsRlc/gwwkVx pHzNdJ1qPifP6yEttVRrnUqX397taIH/Jk8PNW2QBDhMBdxXSwc4Ssk1Oi4LIxUBhZ6VWL z3aVs6xZYcCnW1LJlk7bPIaxL7BY+ts= Received: from mimecast-mx01.redhat.com (mimecast-mx01.redhat.com [209.132.183.4]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-140-zOw8fEgVOxKiHMh8PXUAuw-1; Sat, 04 Apr 2020 10:38:33 -0400 X-MC-Unique: zOw8fEgVOxKiHMh8PXUAuw-1 Received: from smtp.corp.redhat.com (int-mx01.intmail.prod.int.phx2.redhat.com [10.5.11.11]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id 1553A1005509; Sat, 4 Apr 2020 14:38:32 +0000 (UTC) Received: from kamzik.brq.redhat.com (unknown [10.40.192.30]) by smtp.corp.redhat.com (Postfix) with ESMTP id 531BE9B912; Sat, 4 Apr 2020 14:38:30 +0000 (UTC) From: Andrew Jones To: pbonzini@redhat.com Cc: kvm@vger.kernel.org, kvmarm@lists.cs.columbia.edu, Eric Auger Subject: [PULL kvm-unit-tests 22/39] arm: pmu: Test SW_INCR event count Date: Sat, 4 Apr 2020 16:37:14 +0200 Message-Id: <20200404143731.208138-23-drjones@redhat.com> In-Reply-To: <20200404143731.208138-1-drjones@redhat.com> References: <20200404143731.208138-1-drjones@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.11 Sender: kvm-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: kvm@vger.kernel.org From: Eric Auger Add tests dedicated to SW_INCR event counting. Signed-off-by: Eric Auger Signed-off-by: Andrew Jones --- arm/pmu.c | 47 +++++++++++++++++++++++++++++++++++++++++++++++ arm/unittests.cfg | 6 ++++++ 2 files changed, 53 insertions(+) diff --git a/arm/pmu.c b/arm/pmu.c index 4a605c18064f..16d723463395 100644 --- a/arm/pmu.c +++ b/arm/pmu.c @@ -140,6 +140,7 @@ static void test_event_introspection(void) {} static void test_event_counter_config(void) {} static void test_basic_event_count(void) {} static void test_mem_access(void) {} +static void test_sw_incr(void) {} #elif defined(__aarch64__) #define ID_AA64DFR0_PERFMON_SHIFT 8 @@ -463,6 +464,48 @@ static void test_mem_access(void) read_sysreg(pmovsclr_el0)); } +static void test_sw_incr(void) +{ + uint32_t events[] = {SW_INCR, SW_INCR}; + int i; + + if (!satisfy_prerequisites(events, ARRAY_SIZE(events))) + return; + + pmu_reset(); + + write_regn_el0(pmevtyper, 0, SW_INCR | PMEVTYPER_EXCLUDE_EL0); + write_regn_el0(pmevtyper, 1, SW_INCR | PMEVTYPER_EXCLUDE_EL0); + /* enable counters #0 and #1 */ + write_sysreg_s(0x3, PMCNTENSET_EL0); + + write_regn_el0(pmevcntr, 0, PRE_OVERFLOW); + + for (i = 0; i < 100; i++) + write_sysreg(0x1, pmswinc_el0); + + report_info("SW_INCR counter #0 has value %ld", read_regn_el0(pmevcntr, 0)); + report(read_regn_el0(pmevcntr, 0) == PRE_OVERFLOW, + "PWSYNC does not increment if PMCR.E is unset"); + + pmu_reset(); + + write_regn_el0(pmevcntr, 0, PRE_OVERFLOW); + write_sysreg_s(0x3, PMCNTENSET_EL0); + set_pmcr(pmu.pmcr_ro | PMU_PMCR_E); + + for (i = 0; i < 100; i++) + write_sysreg(0x3, pmswinc_el0); + + report(read_regn_el0(pmevcntr, 0) == 84, "counter #1 after + 100 SW_INCR"); + report(read_regn_el0(pmevcntr, 1) == 100, + "counter #0 after + 100 SW_INCR"); + report_info("counter values after 100 SW_INCR #0=%ld #1=%ld", + read_regn_el0(pmevcntr, 0), read_regn_el0(pmevcntr, 1)); + report(read_sysreg(pmovsclr_el0) == 0x1, + "overflow reg after 100 SW_INCR"); +} + #endif /* @@ -649,6 +692,10 @@ int main(int argc, char *argv[]) report_prefix_push(argv[1]); test_mem_access(); report_prefix_pop(); + } else if (strcmp(argv[1], "pmu-sw-incr") == 0) { + report_prefix_push(argv[1]); + test_sw_incr(); + report_prefix_pop(); } else { report_abort("Unknown sub-test '%s'", argv[1]); } diff --git a/arm/unittests.cfg b/arm/unittests.cfg index 32ab8c6fe06a..175afe68225a 100644 --- a/arm/unittests.cfg +++ b/arm/unittests.cfg @@ -90,6 +90,12 @@ groups = pmu arch = arm64 extra_params = -append 'pmu-mem-access' +[pmu-sw-incr] +file = pmu.flat +groups = pmu +arch = arm64 +extra_params = -append 'pmu-sw-incr' + # Test PMU support (TCG) with -icount IPC=1 #[pmu-tcg-icount-1] #file = pmu.flat From patchwork Sat Apr 4 14:37:15 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Andrew Jones X-Patchwork-Id: 11474345 Return-Path: Received: from mail.kernel.org (pdx-korg-mail-1.web.codeaurora.org [172.30.200.123]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id BC59B912 for ; Sat, 4 Apr 2020 14:38:39 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id 91A56206F5 for ; Sat, 4 Apr 2020 14:38:39 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (1024-bit key) header.d=redhat.com header.i=@redhat.com header.b="iCGPH0zF" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726559AbgDDOii (ORCPT ); Sat, 4 Apr 2020 10:38:38 -0400 Received: from us-smtp-2.mimecast.com ([207.211.31.81]:20736 "EHLO us-smtp-delivery-1.mimecast.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S1726481AbgDDOii (ORCPT ); Sat, 4 Apr 2020 10:38:38 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1586011117; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=n+3o8PoghrtRWVjUXbWsW8ZVUhM/vWmMfbc7K3QtvdU=; b=iCGPH0zFItVRyC5448GWWikGeBUVPqDsQzJuRwle06lY9VikZHPA1EG4qYHwPBxprRRKut /PwFOfVrGPMHeFrIk7vQh6zurO9PJ6qzbeCi3hT+RCuC+fQF+281FOqFJsGL5rEngAR2JZ q0naRbaw1eKZ8UnhbdQV488itTAAqyQ= Received: from mimecast-mx01.redhat.com (mimecast-mx01.redhat.com [209.132.183.4]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-187-ZEh05rO8OLqUOEDa7FGbYw-1; Sat, 04 Apr 2020 10:38:35 -0400 X-MC-Unique: ZEh05rO8OLqUOEDa7FGbYw-1 Received: from smtp.corp.redhat.com (int-mx01.intmail.prod.int.phx2.redhat.com [10.5.11.11]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id 704B32F2A; Sat, 4 Apr 2020 14:38:34 +0000 (UTC) Received: from kamzik.brq.redhat.com (unknown [10.40.192.30]) by smtp.corp.redhat.com (Postfix) with ESMTP id 8BC4B1147D3; Sat, 4 Apr 2020 14:38:32 +0000 (UTC) From: Andrew Jones To: pbonzini@redhat.com Cc: kvm@vger.kernel.org, kvmarm@lists.cs.columbia.edu, Eric Auger Subject: [PULL kvm-unit-tests 23/39] arm: pmu: Test chained counters Date: Sat, 4 Apr 2020 16:37:15 +0200 Message-Id: <20200404143731.208138-24-drjones@redhat.com> In-Reply-To: <20200404143731.208138-1-drjones@redhat.com> References: <20200404143731.208138-1-drjones@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.11 Sender: kvm-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: kvm@vger.kernel.org From: Eric Auger Add 2 tests exercising chained counters. The first one uses CPU_CYCLES and the second one uses SW_INCR. Signed-off-by: Eric Auger Signed-off-by: Andrew Jones --- arm/pmu.c | 98 ++++++++++++++++++++++++++++++++++++++++++++++- arm/unittests.cfg | 12 ++++++ 2 files changed, 109 insertions(+), 1 deletion(-) diff --git a/arm/pmu.c b/arm/pmu.c index 16d723463395..73e55498284d 100644 --- a/arm/pmu.c +++ b/arm/pmu.c @@ -47,6 +47,7 @@ #define INST_PREC 0x1B #define STALL_FRONTEND 0x23 #define STALL_BACKEND 0x24 +#define CHAIN 0x1E #define COMMON_EVENTS_LOW 0x0 #define COMMON_EVENTS_HIGH 0x3F @@ -141,6 +142,8 @@ static void test_event_counter_config(void) {} static void test_basic_event_count(void) {} static void test_mem_access(void) {} static void test_sw_incr(void) {} +static void test_chained_counters(void) {} +static void test_chained_sw_incr(void) {} #elif defined(__aarch64__) #define ID_AA64DFR0_PERFMON_SHIFT 8 @@ -503,7 +506,92 @@ static void test_sw_incr(void) report_info("counter values after 100 SW_INCR #0=%ld #1=%ld", read_regn_el0(pmevcntr, 0), read_regn_el0(pmevcntr, 1)); report(read_sysreg(pmovsclr_el0) == 0x1, - "overflow reg after 100 SW_INCR"); + "overflow on counter #0 after 100 SW_INCR"); +} + +static void test_chained_counters(void) +{ + uint32_t events[] = {CPU_CYCLES, CHAIN}; + + if (!satisfy_prerequisites(events, ARRAY_SIZE(events))) + return; + + pmu_reset(); + + write_regn_el0(pmevtyper, 0, CPU_CYCLES | PMEVTYPER_EXCLUDE_EL0); + write_regn_el0(pmevtyper, 1, CHAIN | PMEVTYPER_EXCLUDE_EL0); + /* enable counters #0 and #1 */ + write_sysreg_s(0x3, PMCNTENSET_EL0); + write_regn_el0(pmevcntr, 0, PRE_OVERFLOW); + + precise_instrs_loop(22, pmu.pmcr_ro | PMU_PMCR_E); + + report(read_regn_el0(pmevcntr, 1) == 1, "CHAIN counter #1 incremented"); + report(!read_sysreg(pmovsclr_el0), "no overflow recorded for chained incr #1"); + + /* test 64b overflow */ + + pmu_reset(); + write_sysreg_s(0x3, PMCNTENSET_EL0); + + write_regn_el0(pmevcntr, 0, PRE_OVERFLOW); + write_regn_el0(pmevcntr, 1, 0x1); + precise_instrs_loop(22, pmu.pmcr_ro | PMU_PMCR_E); + report_info("overflow reg = 0x%lx", read_sysreg(pmovsclr_el0)); + report(read_regn_el0(pmevcntr, 1) == 2, "CHAIN counter #1 set to 2"); + report(!read_sysreg(pmovsclr_el0), "no overflow recorded for chained incr #2"); + + write_regn_el0(pmevcntr, 0, PRE_OVERFLOW); + write_regn_el0(pmevcntr, 1, ALL_SET); + + precise_instrs_loop(22, pmu.pmcr_ro | PMU_PMCR_E); + report_info("overflow reg = 0x%lx", read_sysreg(pmovsclr_el0)); + report(!read_regn_el0(pmevcntr, 1), "CHAIN counter #1 wrapped"); + report(read_sysreg(pmovsclr_el0) == 0x2, "overflow on chain counter"); +} + +static void test_chained_sw_incr(void) +{ + uint32_t events[] = {SW_INCR, CHAIN}; + int i; + + if (!satisfy_prerequisites(events, ARRAY_SIZE(events))) + return; + + pmu_reset(); + + write_regn_el0(pmevtyper, 0, SW_INCR | PMEVTYPER_EXCLUDE_EL0); + write_regn_el0(pmevtyper, 1, CHAIN | PMEVTYPER_EXCLUDE_EL0); + /* enable counters #0 and #1 */ + write_sysreg_s(0x3, PMCNTENSET_EL0); + + write_regn_el0(pmevcntr, 0, PRE_OVERFLOW); + set_pmcr(pmu.pmcr_ro | PMU_PMCR_E); + for (i = 0; i < 100; i++) + write_sysreg(0x1, pmswinc_el0); + + report(!read_sysreg(pmovsclr_el0) && (read_regn_el0(pmevcntr, 1) == 1), + "no overflow and chain counter incremented after 100 SW_INCR/CHAIN"); + report_info("overflow=0x%lx, #0=%ld #1=%ld", read_sysreg(pmovsclr_el0), + read_regn_el0(pmevcntr, 0), read_regn_el0(pmevcntr, 1)); + + /* 64b SW_INCR and overflow on CHAIN counter*/ + pmu_reset(); + + write_regn_el0(pmevtyper, 1, events[1] | PMEVTYPER_EXCLUDE_EL0); + write_regn_el0(pmevcntr, 0, PRE_OVERFLOW); + write_regn_el0(pmevcntr, 1, ALL_SET); + write_sysreg_s(0x3, PMCNTENSET_EL0); + set_pmcr(pmu.pmcr_ro | PMU_PMCR_E); + for (i = 0; i < 100; i++) + write_sysreg(0x1, pmswinc_el0); + + report((read_sysreg(pmovsclr_el0) == 0x2) && + (read_regn_el0(pmevcntr, 1) == 0) && + (read_regn_el0(pmevcntr, 0) == 84), + "overflow on chain counter and expected values after 100 SW_INCR/CHAIN"); + report_info("overflow=0x%lx, #0=%ld #1=%ld", read_sysreg(pmovsclr_el0), + read_regn_el0(pmevcntr, 0), read_regn_el0(pmevcntr, 1)); } #endif @@ -696,6 +784,14 @@ int main(int argc, char *argv[]) report_prefix_push(argv[1]); test_sw_incr(); report_prefix_pop(); + } else if (strcmp(argv[1], "pmu-chained-counters") == 0) { + report_prefix_push(argv[1]); + test_chained_counters(); + report_prefix_pop(); + } else if (strcmp(argv[1], "pmu-chained-sw-incr") == 0) { + report_prefix_push(argv[1]); + test_chained_sw_incr(); + report_prefix_pop(); } else { report_abort("Unknown sub-test '%s'", argv[1]); } diff --git a/arm/unittests.cfg b/arm/unittests.cfg index 175afe68225a..d31dcbf6c56f 100644 --- a/arm/unittests.cfg +++ b/arm/unittests.cfg @@ -96,6 +96,18 @@ groups = pmu arch = arm64 extra_params = -append 'pmu-sw-incr' +[pmu-chained-counters] +file = pmu.flat +groups = pmu +arch = arm64 +extra_params = -append 'pmu-chained-counters' + +[pmu-chained-sw-incr] +file = pmu.flat +groups = pmu +arch = arm64 +extra_params = -append 'pmu-chained-sw-incr' + # Test PMU support (TCG) with -icount IPC=1 #[pmu-tcg-icount-1] #file = pmu.flat From patchwork Sat Apr 4 14:37:16 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Andrew Jones X-Patchwork-Id: 11474347 Return-Path: Received: from mail.kernel.org (pdx-korg-mail-1.web.codeaurora.org [172.30.200.123]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 946FB912 for ; Sat, 4 Apr 2020 14:38:45 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id 680EB2071C for ; Sat, 4 Apr 2020 14:38:45 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (1024-bit key) header.d=redhat.com header.i=@redhat.com header.b="cexJCPH1" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726598AbgDDOio (ORCPT ); Sat, 4 Apr 2020 10:38:44 -0400 Received: from us-smtp-1.mimecast.com ([205.139.110.61]:46885 "EHLO us-smtp-delivery-1.mimecast.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S1726132AbgDDOio (ORCPT ); Sat, 4 Apr 2020 10:38:44 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1586011122; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=P9r8K0aGXwOyP5v44zWWM1tcSvLg5nKErcwCi4vPNbw=; b=cexJCPH1Ig8/qnqz3nWduCPKq9iGi2eExKNfhNZuuonDINDFywehHVjH17bgj5RMxuSvjP iJpgzqCSRFADxUHTOe8eInw+h83TwjXl1NFZS1c42OVFEArDroSilZ6O9krMrN8dddky1I A/MoGPi4Ze3vX4G8iafUNmxCo6h9pqw= Received: from mimecast-mx01.redhat.com (mimecast-mx01.redhat.com [209.132.183.4]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-492-TjO25IhqPs65ne43NIXDFg-1; Sat, 04 Apr 2020 10:38:40 -0400 X-MC-Unique: TjO25IhqPs65ne43NIXDFg-1 Received: from smtp.corp.redhat.com (int-mx01.intmail.prod.int.phx2.redhat.com [10.5.11.11]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id 23B4018AB2C0; Sat, 4 Apr 2020 14:38:39 +0000 (UTC) Received: from kamzik.brq.redhat.com (unknown [10.40.192.30]) by smtp.corp.redhat.com (Postfix) with ESMTP id E7FB19B912; Sat, 4 Apr 2020 14:38:34 +0000 (UTC) From: Andrew Jones To: pbonzini@redhat.com Cc: kvm@vger.kernel.org, kvmarm@lists.cs.columbia.edu, Eric Auger Subject: [PULL kvm-unit-tests 24/39] arm: pmu: test 32-bit <-> 64-bit transitions Date: Sat, 4 Apr 2020 16:37:16 +0200 Message-Id: <20200404143731.208138-25-drjones@redhat.com> In-Reply-To: <20200404143731.208138-1-drjones@redhat.com> References: <20200404143731.208138-1-drjones@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.11 Sender: kvm-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: kvm@vger.kernel.org From: Eric Auger Test configurations where we transit from 32b to 64b counters and conversely. Also tests configuration where chain counters are configured but only one counter is enabled. Signed-off-by: Eric Auger Signed-off-by: Andrew Jones --- arm/pmu.c | 138 ++++++++++++++++++++++++++++++++++++++++++++++ arm/unittests.cfg | 6 ++ 2 files changed, 144 insertions(+) diff --git a/arm/pmu.c b/arm/pmu.c index 73e55498284d..9602e70f4185 100644 --- a/arm/pmu.c +++ b/arm/pmu.c @@ -57,6 +57,7 @@ #define ALL_SET 0xFFFFFFFF #define ALL_CLEAR 0x0 #define PRE_OVERFLOW 0xFFFFFFF0 +#define PRE_OVERFLOW2 0xFFFFFFDC struct pmu { unsigned int version; @@ -144,6 +145,7 @@ static void test_mem_access(void) {} static void test_sw_incr(void) {} static void test_chained_counters(void) {} static void test_chained_sw_incr(void) {} +static void test_chain_promotion(void) {} #elif defined(__aarch64__) #define ID_AA64DFR0_PERFMON_SHIFT 8 @@ -594,6 +596,138 @@ static void test_chained_sw_incr(void) read_regn_el0(pmevcntr, 0), read_regn_el0(pmevcntr, 1)); } +static void test_chain_promotion(void) +{ + uint32_t events[] = {MEM_ACCESS, CHAIN}; + void *addr = malloc(PAGE_SIZE); + + if (!satisfy_prerequisites(events, ARRAY_SIZE(events))) + return; + + /* Only enable CHAIN counter */ + pmu_reset(); + write_regn_el0(pmevtyper, 0, MEM_ACCESS | PMEVTYPER_EXCLUDE_EL0); + write_regn_el0(pmevtyper, 1, CHAIN | PMEVTYPER_EXCLUDE_EL0); + write_sysreg_s(0x2, PMCNTENSET_EL0); + isb(); + + mem_access_loop(addr, 20, pmu.pmcr_ro | PMU_PMCR_E); + report(!read_regn_el0(pmevcntr, 0), + "chain counter not counting if even counter is disabled"); + + /* Only enable even counter */ + pmu_reset(); + write_regn_el0(pmevcntr, 0, PRE_OVERFLOW); + write_sysreg_s(0x1, PMCNTENSET_EL0); + isb(); + + mem_access_loop(addr, 20, pmu.pmcr_ro | PMU_PMCR_E); + report(!read_regn_el0(pmevcntr, 1) && (read_sysreg(pmovsclr_el0) == 0x1), + "odd counter did not increment on overflow if disabled"); + report_info("MEM_ACCESS counter #0 has value %ld", + read_regn_el0(pmevcntr, 0)); + report_info("CHAIN counter #1 has value %ld", + read_regn_el0(pmevcntr, 1)); + report_info("overflow counter %ld", read_sysreg(pmovsclr_el0)); + + /* start at 0xFFFFFFDC, +20 with CHAIN enabled, +20 with CHAIN disabled */ + pmu_reset(); + write_sysreg_s(0x3, PMCNTENSET_EL0); + write_regn_el0(pmevcntr, 0, PRE_OVERFLOW2); + isb(); + + mem_access_loop(addr, 20, pmu.pmcr_ro | PMU_PMCR_E); + report_info("MEM_ACCESS counter #0 has value 0x%lx", + read_regn_el0(pmevcntr, 0)); + + /* disable the CHAIN event */ + write_sysreg_s(0x2, PMCNTENCLR_EL0); + mem_access_loop(addr, 20, pmu.pmcr_ro | PMU_PMCR_E); + report_info("MEM_ACCESS counter #0 has value 0x%lx", + read_regn_el0(pmevcntr, 0)); + report(read_sysreg(pmovsclr_el0) == 0x1, + "should have triggered an overflow on #0"); + report(!read_regn_el0(pmevcntr, 1), + "CHAIN counter #1 shouldn't have incremented"); + + /* start at 0xFFFFFFDC, +20 with CHAIN disabled, +20 with CHAIN enabled */ + + pmu_reset(); + write_sysreg_s(0x1, PMCNTENSET_EL0); + write_regn_el0(pmevcntr, 0, PRE_OVERFLOW2); + isb(); + report_info("counter #0 = 0x%lx, counter #1 = 0x%lx overflow=0x%lx", + read_regn_el0(pmevcntr, 0), read_regn_el0(pmevcntr, 1), + read_sysreg(pmovsclr_el0)); + + mem_access_loop(addr, 20, pmu.pmcr_ro | PMU_PMCR_E); + report_info("MEM_ACCESS counter #0 has value 0x%lx", + read_regn_el0(pmevcntr, 0)); + + /* enable the CHAIN event */ + write_sysreg_s(0x3, PMCNTENSET_EL0); + isb(); + mem_access_loop(addr, 20, pmu.pmcr_ro | PMU_PMCR_E); + report_info("MEM_ACCESS counter #0 has value 0x%lx", + read_regn_el0(pmevcntr, 0)); + + report((read_regn_el0(pmevcntr, 1) == 1) && !read_sysreg(pmovsclr_el0), + "CHAIN counter enabled: CHAIN counter was incremented and no overflow"); + + report_info("CHAIN counter #1 = 0x%lx, overflow=0x%lx", + read_regn_el0(pmevcntr, 1), read_sysreg(pmovsclr_el0)); + + /* start as MEM_ACCESS/CPU_CYCLES and move to CHAIN/MEM_ACCESS */ + pmu_reset(); + write_regn_el0(pmevtyper, 0, MEM_ACCESS | PMEVTYPER_EXCLUDE_EL0); + write_regn_el0(pmevtyper, 1, CPU_CYCLES | PMEVTYPER_EXCLUDE_EL0); + write_sysreg_s(0x3, PMCNTENSET_EL0); + write_regn_el0(pmevcntr, 0, PRE_OVERFLOW2); + isb(); + + mem_access_loop(addr, 20, pmu.pmcr_ro | PMU_PMCR_E); + report_info("MEM_ACCESS counter #0 has value 0x%lx", + read_regn_el0(pmevcntr, 0)); + + /* 0 becomes CHAINED */ + write_sysreg_s(0x0, PMCNTENSET_EL0); + write_regn_el0(pmevtyper, 1, CHAIN | PMEVTYPER_EXCLUDE_EL0); + write_sysreg_s(0x3, PMCNTENSET_EL0); + write_regn_el0(pmevcntr, 1, 0x0); + + mem_access_loop(addr, 20, pmu.pmcr_ro | PMU_PMCR_E); + report_info("MEM_ACCESS counter #0 has value 0x%lx", + read_regn_el0(pmevcntr, 0)); + + report((read_regn_el0(pmevcntr, 1) == 1) && !read_sysreg(pmovsclr_el0), + "32b->64b: CHAIN counter incremented and no overflow"); + + report_info("CHAIN counter #1 = 0x%lx, overflow=0x%lx", + read_regn_el0(pmevcntr, 1), read_sysreg(pmovsclr_el0)); + + /* start as CHAIN/MEM_ACCESS and move to MEM_ACCESS/CPU_CYCLES */ + pmu_reset(); + write_regn_el0(pmevtyper, 0, MEM_ACCESS | PMEVTYPER_EXCLUDE_EL0); + write_regn_el0(pmevtyper, 1, CHAIN | PMEVTYPER_EXCLUDE_EL0); + write_regn_el0(pmevcntr, 0, PRE_OVERFLOW2); + write_sysreg_s(0x3, PMCNTENSET_EL0); + + mem_access_loop(addr, 20, pmu.pmcr_ro | PMU_PMCR_E); + report_info("counter #0=0x%lx, counter #1=0x%lx", + read_regn_el0(pmevcntr, 0), read_regn_el0(pmevcntr, 1)); + + write_sysreg_s(0x0, PMCNTENSET_EL0); + write_regn_el0(pmevtyper, 1, CPU_CYCLES | PMEVTYPER_EXCLUDE_EL0); + write_sysreg_s(0x3, PMCNTENSET_EL0); + + mem_access_loop(addr, 20, pmu.pmcr_ro | PMU_PMCR_E); + report(read_sysreg(pmovsclr_el0) == 1, + "overflow is expected on counter 0"); + report_info("counter #0=0x%lx, counter #1=0x%lx overflow=0x%lx", + read_regn_el0(pmevcntr, 0), read_regn_el0(pmevcntr, 1), + read_sysreg(pmovsclr_el0)); +} + #endif /* @@ -792,6 +926,10 @@ int main(int argc, char *argv[]) report_prefix_push(argv[1]); test_chained_sw_incr(); report_prefix_pop(); + } else if (strcmp(argv[1], "pmu-chain-promotion") == 0) { + report_prefix_push(argv[1]); + test_chain_promotion(); + report_prefix_pop(); } else { report_abort("Unknown sub-test '%s'", argv[1]); } diff --git a/arm/unittests.cfg b/arm/unittests.cfg index d31dcbf6c56f..1b0c8c8c7eef 100644 --- a/arm/unittests.cfg +++ b/arm/unittests.cfg @@ -108,6 +108,12 @@ groups = pmu arch = arm64 extra_params = -append 'pmu-chained-sw-incr' +[pmu-chain-promotion] +file = pmu.flat +groups = pmu +arch = arm64 +extra_params = -append 'pmu-chain-promotion' + # Test PMU support (TCG) with -icount IPC=1 #[pmu-tcg-icount-1] #file = pmu.flat From patchwork Sat Apr 4 14:37:17 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Andrew Jones X-Patchwork-Id: 11474349 Return-Path: Received: from mail.kernel.org (pdx-korg-mail-1.web.codeaurora.org [172.30.200.123]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id A554B1392 for ; Sat, 4 Apr 2020 14:38:46 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id 81E9F206F5 for ; Sat, 4 Apr 2020 14:38:46 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (1024-bit key) header.d=redhat.com header.i=@redhat.com header.b="E7UDU0aX" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726599AbgDDOip (ORCPT ); Sat, 4 Apr 2020 10:38:45 -0400 Received: from us-smtp-delivery-1.mimecast.com ([205.139.110.120]:23457 "EHLO us-smtp-1.mimecast.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S1726605AbgDDOip (ORCPT ); Sat, 4 Apr 2020 10:38:45 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1586011124; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=1LCVI6Q4/Ny0Rm6fGm4deZaX1vxgVnpBC6xTC+/9SMI=; b=E7UDU0aXO7PC8iQxb8nnWLg/j2NRgex0QZt4yW/6/05E8xzV21S/4JLFsePeNvx2DMdA0k IXQCEGxCQMetD3lkPQCYTEy9Uibyf0o+2nw1kn1juJUkNvrToObZv/4wFCewvB2v0qY68Q KXatm4XmH+8hiyttY3Vx7Zfe1ujDNJ0= Received: from mimecast-mx01.redhat.com (mimecast-mx01.redhat.com [209.132.183.4]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-26-ps8eJ8gOO--NCAUGHPGUAA-1; Sat, 04 Apr 2020 10:38:42 -0400 X-MC-Unique: ps8eJ8gOO--NCAUGHPGUAA-1 Received: from smtp.corp.redhat.com (int-mx01.intmail.prod.int.phx2.redhat.com [10.5.11.11]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id 6187E1005513; Sat, 4 Apr 2020 14:38:41 +0000 (UTC) Received: from kamzik.brq.redhat.com (unknown [10.40.192.30]) by smtp.corp.redhat.com (Postfix) with ESMTP id 9C2D79B912; Sat, 4 Apr 2020 14:38:39 +0000 (UTC) From: Andrew Jones To: pbonzini@redhat.com Cc: kvm@vger.kernel.org, kvmarm@lists.cs.columbia.edu, Eric Auger Subject: [PULL kvm-unit-tests 25/39] arm: gic: Introduce gic_irq_set_clr_enable() helper Date: Sat, 4 Apr 2020 16:37:17 +0200 Message-Id: <20200404143731.208138-26-drjones@redhat.com> In-Reply-To: <20200404143731.208138-1-drjones@redhat.com> References: <20200404143731.208138-1-drjones@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.11 Sender: kvm-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: kvm@vger.kernel.org From: Eric Auger Allows to set or clear the enable state of a PPI/SGI/SPI. Signed-off-by: Eric Auger Signed-off-by: Andrew Jones --- lib/arm/asm/gic.h | 4 ++++ lib/arm/gic.c | 31 +++++++++++++++++++++++++++++++ 2 files changed, 35 insertions(+) diff --git a/lib/arm/asm/gic.h b/lib/arm/asm/gic.h index 922cbe95750c..afb33096078d 100644 --- a/lib/arm/asm/gic.h +++ b/lib/arm/asm/gic.h @@ -82,5 +82,9 @@ extern void gic_ipi_send_single(int irq, int cpu); extern void gic_ipi_send_mask(int irq, const cpumask_t *dest); extern enum gic_irq_state gic_irq_state(int irq); +void gic_irq_set_clr_enable(int irq, bool enable); +#define gic_enable_irq(irq) gic_irq_set_clr_enable(irq, true) +#define gic_disable_irq(irq) gic_irq_set_clr_enable(irq, false) + #endif /* !__ASSEMBLY__ */ #endif /* _ASMARM_GIC_H_ */ diff --git a/lib/arm/gic.c b/lib/arm/gic.c index c3c5f6bc5b0e..8a1a8c84bf29 100644 --- a/lib/arm/gic.c +++ b/lib/arm/gic.c @@ -147,6 +147,36 @@ void gic_ipi_send_mask(int irq, const cpumask_t *dest) gic_common_ops->ipi_send_mask(irq, dest); } +void gic_irq_set_clr_enable(int irq, bool enable) +{ + u32 offset, split = 32, shift = (irq % 32); + u32 reg, mask = BIT(shift); + void *base; + + assert(irq < 1020); + + switch (gic_version()) { + case 2: + offset = enable ? GICD_ISENABLER : GICD_ICENABLER; + base = gicv2_dist_base(); + break; + case 3: + if (irq < 32) { + offset = enable ? GICR_ISENABLER0 : GICR_ICENABLER0; + base = gicv3_sgi_base(); + } else { + offset = enable ? GICD_ISENABLER : GICD_ICENABLER; + base = gicv3_dist_base(); + } + break; + default: + assert(0); + } + base += offset + (irq / split) * 4; + reg = readl(base); + writel(reg | mask, base); +} + enum gic_irq_state gic_irq_state(int irq) { enum gic_irq_state state; @@ -191,3 +221,4 @@ enum gic_irq_state gic_irq_state(int irq) return state; } + From patchwork Sat Apr 4 14:37:18 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Andrew Jones X-Patchwork-Id: 11474353 Return-Path: Received: from mail.kernel.org (pdx-korg-mail-1.web.codeaurora.org [172.30.200.123]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 991BC912 for ; Sat, 4 Apr 2020 14:38:49 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id 77D1D20738 for ; Sat, 4 Apr 2020 14:38:49 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (1024-bit key) header.d=redhat.com header.i=@redhat.com header.b="Lzs9e61X" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726634AbgDDOit (ORCPT ); Sat, 4 Apr 2020 10:38:49 -0400 Received: from us-smtp-1.mimecast.com ([207.211.31.81]:41388 "EHLO us-smtp-delivery-1.mimecast.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S1726485AbgDDOis (ORCPT ); Sat, 4 Apr 2020 10:38:48 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1586011127; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=o/HtE4kD9Ya8MkHXVocYcKIgEQVisPRhIPUyZlQYN94=; b=Lzs9e61XzaoZFe3xpXSFLPpm3G9id16dKyw+C4qHPJ9FGnUnpTP9Z5aMFPSZ64aWpTt861 JZM0OCcYbjINvBko6u/XTlpHTdIKdId4scY9mbfy3CJa0ShOOcN7BSOmFUxczPGx3HNF5b J+lxG04j7YvnSiJAfSVkhAYc1CaNO3U= Received: from mimecast-mx01.redhat.com (mimecast-mx01.redhat.com [209.132.183.4]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-395-Dqa0rjBvOBe8HVdERkn99Q-1; Sat, 04 Apr 2020 10:38:44 -0400 X-MC-Unique: Dqa0rjBvOBe8HVdERkn99Q-1 Received: from smtp.corp.redhat.com (int-mx01.intmail.prod.int.phx2.redhat.com [10.5.11.11]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id BEC2E107ACC7; Sat, 4 Apr 2020 14:38:43 +0000 (UTC) Received: from kamzik.brq.redhat.com (unknown [10.40.192.30]) by smtp.corp.redhat.com (Postfix) with ESMTP id DB9079B912; Sat, 4 Apr 2020 14:38:41 +0000 (UTC) From: Andrew Jones To: pbonzini@redhat.com Cc: kvm@vger.kernel.org, kvmarm@lists.cs.columbia.edu, Eric Auger Subject: [PULL kvm-unit-tests 26/39] arm: pmu: Test overflow interrupts Date: Sat, 4 Apr 2020 16:37:18 +0200 Message-Id: <20200404143731.208138-27-drjones@redhat.com> In-Reply-To: <20200404143731.208138-1-drjones@redhat.com> References: <20200404143731.208138-1-drjones@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.11 Sender: kvm-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: kvm@vger.kernel.org From: Eric Auger Test overflows for MEM_ACCESS and SW_INCR events. Also tests overflows with 64-bit events. Signed-off-by: Eric Auger Signed-off-by: Andrew Jones --- arm/pmu.c | 139 ++++++++++++++++++++++++++++++++++++++++++++++ arm/unittests.cfg | 6 ++ 2 files changed, 145 insertions(+) diff --git a/arm/pmu.c b/arm/pmu.c index 9602e70f4185..cece53ef6431 100644 --- a/arm/pmu.c +++ b/arm/pmu.c @@ -59,12 +59,20 @@ #define PRE_OVERFLOW 0xFFFFFFF0 #define PRE_OVERFLOW2 0xFFFFFFDC +#define PMU_PPI 23 + struct pmu { unsigned int version; unsigned int nb_implemented_counters; uint32_t pmcr_ro; }; +struct pmu_stats { + unsigned long bitmap; + uint32_t interrupts[32]; + bool unexpected; +}; + static struct pmu pmu; #if defined(__arm__) @@ -146,6 +154,7 @@ static void test_sw_incr(void) {} static void test_chained_counters(void) {} static void test_chained_sw_incr(void) {} static void test_chain_promotion(void) {} +static void test_overflow_interrupt(void) {} #elif defined(__aarch64__) #define ID_AA64DFR0_PERFMON_SHIFT 8 @@ -276,6 +285,43 @@ asm volatile( : "x9", "x10", "cc"); } +static struct pmu_stats pmu_stats; + +static void irq_handler(struct pt_regs *regs) +{ + uint32_t irqstat, irqnr; + + irqstat = gic_read_iar(); + irqnr = gic_iar_irqnr(irqstat); + + if (irqnr == PMU_PPI) { + unsigned long overflows = read_sysreg(pmovsclr_el0); + int i; + + for (i = 0; i < 32; i++) { + if (test_and_clear_bit(i, &overflows)) { + pmu_stats.interrupts[i]++; + pmu_stats.bitmap |= 1 << i; + } + } + write_sysreg(ALL_SET, pmovsclr_el0); + } else { + pmu_stats.unexpected = true; + } + gic_write_eoir(irqstat); +} + +static void pmu_reset_stats(void) +{ + int i; + + for (i = 0; i < 32; i++) + pmu_stats.interrupts[i] = 0; + + pmu_stats.bitmap = 0; + pmu_stats.unexpected = false; +} + static void pmu_reset(void) { /* reset all counters, counting disabled at PMCR level*/ @@ -286,6 +332,7 @@ static void pmu_reset(void) write_sysreg(ALL_SET, pmovsclr_el0); /* disable overflow interrupts on all counters */ write_sysreg(ALL_SET, pmintenclr_el1); + pmu_reset_stats(); isb(); } @@ -728,6 +775,94 @@ static void test_chain_promotion(void) read_sysreg(pmovsclr_el0)); } +static bool expect_interrupts(uint32_t bitmap) +{ + int i; + + if (pmu_stats.bitmap ^ bitmap || pmu_stats.unexpected) + return false; + + for (i = 0; i < 32; i++) { + if (test_and_clear_bit(i, &pmu_stats.bitmap)) + if (pmu_stats.interrupts[i] != 1) + return false; + } + return true; +} + +static void test_overflow_interrupt(void) +{ + uint32_t events[] = {MEM_ACCESS, SW_INCR}; + void *addr = malloc(PAGE_SIZE); + int i; + + if (!satisfy_prerequisites(events, ARRAY_SIZE(events))) + return; + + gic_enable_defaults(); + install_irq_handler(EL1H_IRQ, irq_handler); + local_irq_enable(); + gic_enable_irq(23); + + pmu_reset(); + + write_regn_el0(pmevtyper, 0, MEM_ACCESS | PMEVTYPER_EXCLUDE_EL0); + write_regn_el0(pmevtyper, 1, SW_INCR | PMEVTYPER_EXCLUDE_EL0); + write_sysreg_s(0x3, PMCNTENSET_EL0); + write_regn_el0(pmevcntr, 0, PRE_OVERFLOW); + write_regn_el0(pmevcntr, 1, PRE_OVERFLOW); + isb(); + + /* interrupts are disabled */ + + mem_access_loop(addr, 200, pmu.pmcr_ro | PMU_PMCR_E); + report(expect_interrupts(0), "no overflow interrupt after preset"); + + set_pmcr(pmu.pmcr_ro | PMU_PMCR_E); + for (i = 0; i < 100; i++) + write_sysreg(0x2, pmswinc_el0); + + set_pmcr(pmu.pmcr_ro); + report(expect_interrupts(0), "no overflow interrupt after counting"); + + /* enable interrupts */ + + pmu_reset_stats(); + + write_regn_el0(pmevcntr, 0, PRE_OVERFLOW); + write_regn_el0(pmevcntr, 1, PRE_OVERFLOW); + write_sysreg(ALL_SET, pmintenset_el1); + isb(); + + mem_access_loop(addr, 200, pmu.pmcr_ro | PMU_PMCR_E); + for (i = 0; i < 100; i++) + write_sysreg(0x3, pmswinc_el0); + + mem_access_loop(addr, 200, pmu.pmcr_ro); + report_info("overflow=0x%lx", read_sysreg(pmovsclr_el0)); + report(expect_interrupts(0x3), + "overflow interrupts expected on #0 and #1"); + + /* promote to 64-b */ + + pmu_reset_stats(); + + write_regn_el0(pmevtyper, 1, CHAIN | PMEVTYPER_EXCLUDE_EL0); + write_regn_el0(pmevcntr, 0, PRE_OVERFLOW); + isb(); + mem_access_loop(addr, 200, pmu.pmcr_ro | PMU_PMCR_E); + report(expect_interrupts(0), + "no overflow interrupt expected on 32b boundary"); + + /* overflow on odd counter */ + pmu_reset_stats(); + write_regn_el0(pmevcntr, 0, PRE_OVERFLOW); + write_regn_el0(pmevcntr, 1, ALL_SET); + isb(); + mem_access_loop(addr, 400, pmu.pmcr_ro | PMU_PMCR_E); + report(expect_interrupts(0x2), + "expect overflow interrupt on odd counter"); +} #endif /* @@ -930,6 +1065,10 @@ int main(int argc, char *argv[]) report_prefix_push(argv[1]); test_chain_promotion(); report_prefix_pop(); + } else if (strcmp(argv[1], "pmu-overflow-interrupt") == 0) { + report_prefix_push(argv[1]); + test_overflow_interrupt(); + report_prefix_pop(); } else { report_abort("Unknown sub-test '%s'", argv[1]); } diff --git a/arm/unittests.cfg b/arm/unittests.cfg index 1b0c8c8c7eef..455fd10d63c9 100644 --- a/arm/unittests.cfg +++ b/arm/unittests.cfg @@ -114,6 +114,12 @@ groups = pmu arch = arm64 extra_params = -append 'pmu-chain-promotion' +[pmu-overflow-interrupt] +file = pmu.flat +groups = pmu +arch = arm64 +extra_params = -append 'pmu-overflow-interrupt' + # Test PMU support (TCG) with -icount IPC=1 #[pmu-tcg-icount-1] #file = pmu.flat From patchwork Sat Apr 4 14:37:19 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Andrew Jones X-Patchwork-Id: 11474355 Return-Path: Received: from mail.kernel.org (pdx-korg-mail-1.web.codeaurora.org [172.30.200.123]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id A71CE1392 for ; Sat, 4 Apr 2020 14:38:51 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id 7B26C2070E for ; Sat, 4 Apr 2020 14:38:51 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (1024-bit key) header.d=redhat.com header.i=@redhat.com header.b="Yqz37f6Z" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726641AbgDDOiv (ORCPT ); Sat, 4 Apr 2020 10:38:51 -0400 Received: from us-smtp-2.mimecast.com ([207.211.31.81]:47565 "EHLO us-smtp-delivery-1.mimecast.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S1726556AbgDDOiu (ORCPT ); Sat, 4 Apr 2020 10:38:50 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1586011129; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=E61LdlhYu0YVZ8oHJ7mKk5gQ83vLoqlUH5GgQLrc3V0=; b=Yqz37f6ZUmR+hFUct38zM/rILbFc/BKvHNkfg3CVVnPQnOJeEV1jsQL2Hi8T/Vp8fs2uf4 A+E/kPJw4CknDaYeo09W15wfQQr2a/i9t+paDC0mk6AIIg8NqliMBuK7lfpJA71IP3fckD y97eVlKVIRL2i2Ui10TJhGb0QX5x5bU= Received: from mimecast-mx01.redhat.com (mimecast-mx01.redhat.com [209.132.183.4]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-365-LO2PLRBaPnKVRlfc3xm7Rg-1; Sat, 04 Apr 2020 10:38:47 -0400 X-MC-Unique: LO2PLRBaPnKVRlfc3xm7Rg-1 Received: from smtp.corp.redhat.com (int-mx01.intmail.prod.int.phx2.redhat.com [10.5.11.11]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id 6B44F18AB2C3; Sat, 4 Apr 2020 14:38:46 +0000 (UTC) Received: from kamzik.brq.redhat.com (unknown [10.40.192.30]) by smtp.corp.redhat.com (Postfix) with ESMTP id 3D0FF1147D3; Sat, 4 Apr 2020 14:38:44 +0000 (UTC) From: Andrew Jones To: pbonzini@redhat.com Cc: kvm@vger.kernel.org, kvmarm@lists.cs.columbia.edu, Eric Auger , Thomas Huth Subject: [PULL kvm-unit-tests 27/39] libcflat: Add other size defines Date: Sat, 4 Apr 2020 16:37:19 +0200 Message-Id: <20200404143731.208138-28-drjones@redhat.com> In-Reply-To: <20200404143731.208138-1-drjones@redhat.com> References: <20200404143731.208138-1-drjones@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.11 Sender: kvm-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: kvm@vger.kernel.org From: Eric Auger Introduce additional SZ_256, SZ_8K, SZ_16K macros that will be used by ITS tests. Signed-off-by: Eric Auger Reviewed-by: Thomas Huth Signed-off-by: Andrew Jones --- lib/libcflat.h | 3 +++ 1 file changed, 3 insertions(+) diff --git a/lib/libcflat.h b/lib/libcflat.h index ea19f618b193..7092af2d8c38 100644 --- a/lib/libcflat.h +++ b/lib/libcflat.h @@ -36,7 +36,10 @@ #define ALIGN(x, a) __ALIGN((x), (a)) #define IS_ALIGNED(x, a) (((x) & ((typeof(x))(a) - 1)) == 0) +#define SZ_256 (1 << 8) #define SZ_4K (1 << 12) +#define SZ_8K (1 << 13) +#define SZ_16K (1 << 14) #define SZ_64K (1 << 16) #define SZ_2M (1 << 21) #define SZ_1G (1 << 30) From patchwork Sat Apr 4 14:37:20 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Andrew Jones X-Patchwork-Id: 11474357 Return-Path: Received: from mail.kernel.org (pdx-korg-mail-1.web.codeaurora.org [172.30.200.123]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 09B9A1392 for ; Sat, 4 Apr 2020 14:38:54 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id D34042071C for ; Sat, 4 Apr 2020 14:38:53 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (1024-bit key) header.d=redhat.com header.i=@redhat.com header.b="DXYcLgFq" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726608AbgDDOix (ORCPT ); Sat, 4 Apr 2020 10:38:53 -0400 Received: from us-smtp-1.mimecast.com ([205.139.110.61]:50441 "EHLO us-smtp-delivery-1.mimecast.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S1726485AbgDDOiw (ORCPT ); Sat, 4 Apr 2020 10:38:52 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1586011131; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=Q5CT8J6SynPPib2nGk/jJo1msopT0GvmIwP+jVblkEA=; b=DXYcLgFqWh0JqgvTZ2JPSW3rHoUHoeNdCGvXNOl909JHnlq9Ri5+AxW4xtsiOaRpNX8RuU /D/LABuZs6J3pzZExOouaXJMKKw2MrPWVdrXAJeXGHejLPU7ykW7XLw2q6GENJbRtH2WEO 52wc/fWF0RRmlyP84w2EvRQOI70LJBM= Received: from mimecast-mx01.redhat.com (mimecast-mx01.redhat.com [209.132.183.4]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-454-jvfHukaSObSekUMTEQIKnw-1; Sat, 04 Apr 2020 10:38:49 -0400 X-MC-Unique: jvfHukaSObSekUMTEQIKnw-1 Received: from smtp.corp.redhat.com (int-mx01.intmail.prod.int.phx2.redhat.com [10.5.11.11]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id 7887C107ACC7; Sat, 4 Apr 2020 14:38:48 +0000 (UTC) Received: from kamzik.brq.redhat.com (unknown [10.40.192.30]) by smtp.corp.redhat.com (Postfix) with ESMTP id E34B59B912; Sat, 4 Apr 2020 14:38:46 +0000 (UTC) From: Andrew Jones To: pbonzini@redhat.com Cc: kvm@vger.kernel.org, kvmarm@lists.cs.columbia.edu, Eric Auger Subject: [PULL kvm-unit-tests 28/39] page_alloc: Introduce get_order() Date: Sat, 4 Apr 2020 16:37:20 +0200 Message-Id: <20200404143731.208138-29-drjones@redhat.com> In-Reply-To: <20200404143731.208138-1-drjones@redhat.com> References: <20200404143731.208138-1-drjones@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.11 Sender: kvm-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: kvm@vger.kernel.org From: Eric Auger Compute the power of 2 order of a size. Use it in page_memalign. Other users are looming. Signed-off-by: Eric Auger Signed-off-by: Andrew Jones --- lib/alloc_page.c | 7 ++++++- lib/alloc_page.h | 1 + 2 files changed, 7 insertions(+), 1 deletion(-) diff --git a/lib/alloc_page.c b/lib/alloc_page.c index ed236389537e..7c8461aa759c 100644 --- a/lib/alloc_page.c +++ b/lib/alloc_page.c @@ -155,7 +155,7 @@ static void *page_memalign(size_t alignment, size_t size) if (!size) return NULL; - order = is_power_of_2(n) ? fls(n) : fls(n) + 1; + order = get_order(n); return alloc_pages(order); } @@ -175,3 +175,8 @@ void page_alloc_ops_enable(void) { alloc_ops = &page_alloc_ops; } + +int get_order(size_t size) +{ + return is_power_of_2(size) ? fls(size) : fls(size) + 1; +} diff --git a/lib/alloc_page.h b/lib/alloc_page.h index 739a91def979..e6a51d2bc270 100644 --- a/lib/alloc_page.h +++ b/lib/alloc_page.h @@ -15,5 +15,6 @@ void *alloc_pages(unsigned long order); void free_page(void *page); void free_pages(void *mem, unsigned long size); void free_pages_by_order(void *mem, unsigned long order); +int get_order(size_t size); #endif From patchwork Sat Apr 4 14:37:21 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Andrew Jones X-Patchwork-Id: 11474359 Return-Path: Received: from mail.kernel.org (pdx-korg-mail-1.web.codeaurora.org [172.30.200.123]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 0C9BC912 for ; Sat, 4 Apr 2020 14:39:01 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id DF3172070E for ; Sat, 4 Apr 2020 14:39:00 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (1024-bit key) header.d=redhat.com header.i=@redhat.com header.b="GyIqwxwu" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726620AbgDDOjA (ORCPT ); Sat, 4 Apr 2020 10:39:00 -0400 Received: from us-smtp-delivery-1.mimecast.com ([205.139.110.120]:28061 "EHLO us-smtp-1.mimecast.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S1726651AbgDDOi7 (ORCPT ); Sat, 4 Apr 2020 10:38:59 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1586011138; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=l8n0ox4EOitW9lrwS5OEfDDUam5i4CZC8gSz+9RvIe0=; b=GyIqwxwuQMScxKEXS5fEYmKavr1CzsxDNz+6bYig1HHVj64pALyRiIsntul67QgLxuvxHJ DfttvGFiqlng/SaRFcVyqg5B1r0uzgymGBGoij3mOfCrPVqAOcruxN2Uz328KfLGjoQR9E A4O2Iz1UBa3MXtdx/4e/eJe4/t+NS7w= Received: from mimecast-mx01.redhat.com (mimecast-mx01.redhat.com [209.132.183.4]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-156-fqN0UavENrCldXlHuRN00A-1; Sat, 04 Apr 2020 10:38:56 -0400 X-MC-Unique: fqN0UavENrCldXlHuRN00A-1 Received: from smtp.corp.redhat.com (int-mx01.intmail.prod.int.phx2.redhat.com [10.5.11.11]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id 564BB107B27C; Sat, 4 Apr 2020 14:38:55 +0000 (UTC) Received: from kamzik.brq.redhat.com (unknown [10.40.192.30]) by smtp.corp.redhat.com (Postfix) with ESMTP id EEC061147D3; Sat, 4 Apr 2020 14:38:48 +0000 (UTC) From: Andrew Jones To: pbonzini@redhat.com Cc: kvm@vger.kernel.org, kvmarm@lists.cs.columbia.edu, Eric Auger Subject: [PULL kvm-unit-tests 29/39] arm/arm64: gic: Introduce setup_irq() helper Date: Sat, 4 Apr 2020 16:37:21 +0200 Message-Id: <20200404143731.208138-30-drjones@redhat.com> In-Reply-To: <20200404143731.208138-1-drjones@redhat.com> References: <20200404143731.208138-1-drjones@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.11 Sender: kvm-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: kvm@vger.kernel.org From: Eric Auger ipi_enable() code would be reusable for other interrupts than IPI. Let's rename it setup_irq() and pass an interrupt handler pointer. Signed-off-by: Eric Auger Signed-off-by: Andrew Jones --- arm/gic.c | 19 ++++++------------- lib/arm/asm/processor.h | 2 ++ 2 files changed, 8 insertions(+), 13 deletions(-) diff --git a/arm/gic.c b/arm/gic.c index fcf4c1ff3875..2f904b0ef375 100644 --- a/arm/gic.c +++ b/arm/gic.c @@ -215,20 +215,20 @@ static void ipi_test_smp(void) report_prefix_pop(); } -static void ipi_enable(void) +static void setup_irq(irq_handler_fn handler) { gic_enable_defaults(); #ifdef __arm__ - install_exception_handler(EXCPTN_IRQ, ipi_handler); + install_exception_handler(EXCPTN_IRQ, handler); #else - install_irq_handler(EL1H_IRQ, ipi_handler); + install_irq_handler(EL1H_IRQ, handler); #endif local_irq_enable(); } static void ipi_send(void) { - ipi_enable(); + setup_irq(ipi_handler); wait_on_ready(); ipi_test_self(); ipi_test_smp(); @@ -238,7 +238,7 @@ static void ipi_send(void) static void ipi_recv(void) { - ipi_enable(); + setup_irq(ipi_handler); cpumask_set_cpu(smp_processor_id(), &ready); while (1) wfi(); @@ -295,14 +295,7 @@ static void ipi_clear_active_handler(struct pt_regs *regs __unused) static void run_active_clear_test(void) { report_prefix_push("active"); - gic_enable_defaults(); -#ifdef __arm__ - install_exception_handler(EXCPTN_IRQ, ipi_clear_active_handler); -#else - install_irq_handler(EL1H_IRQ, ipi_clear_active_handler); -#endif - local_irq_enable(); - + setup_irq(ipi_clear_active_handler); ipi_test_self(); report_prefix_pop(); } diff --git a/lib/arm/asm/processor.h b/lib/arm/asm/processor.h index 1e1132dafd2b..e26ef89000a8 100644 --- a/lib/arm/asm/processor.h +++ b/lib/arm/asm/processor.h @@ -26,7 +26,9 @@ enum vector { EXCPTN_MAX, }; +typedef void (*irq_handler_fn)(struct pt_regs *regs); typedef void (*exception_fn)(struct pt_regs *); + extern void install_exception_handler(enum vector v, exception_fn fn); extern void show_regs(struct pt_regs *regs); From patchwork Sat Apr 4 14:37:22 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Andrew Jones X-Patchwork-Id: 11474361 Return-Path: Received: from mail.kernel.org (pdx-korg-mail-1.web.codeaurora.org [172.30.200.123]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 827AE912 for ; Sat, 4 Apr 2020 14:39:13 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id 615552070E for ; Sat, 4 Apr 2020 14:39:13 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (1024-bit key) header.d=redhat.com header.i=@redhat.com header.b="L58PRhBR" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726535AbgDDOjM (ORCPT ); Sat, 4 Apr 2020 10:39:12 -0400 Received: from us-smtp-2.mimecast.com ([207.211.31.81]:36272 "EHLO us-smtp-delivery-1.mimecast.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S1726327AbgDDOjM (ORCPT ); Sat, 4 Apr 2020 10:39:12 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1586011151; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=KQ0mK9IV0hAU4wWwyKmtnZUricrGKLp5YosiOwcXox4=; b=L58PRhBRRmbZFRZwf5xDCEQZW6xPjA/OTRn3j6+/dsquaFSEQ0X/ojIprDep8SSrk7rD0N 6Qt1WbOOm6CRaUELkxrX45w7547Gc9HCknKHpF3QC7zuUMp6tUsLYFAkKAt8tg2RNlRcr0 dr+zbQJWO55foLg9owS0rWdLrkNVZms= Received: from mimecast-mx01.redhat.com (mimecast-mx01.redhat.com [209.132.183.4]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-195-a-13OabHNIipbZTuUU2pcw-1; Sat, 04 Apr 2020 10:39:06 -0400 X-MC-Unique: a-13OabHNIipbZTuUU2pcw-1 Received: from smtp.corp.redhat.com (int-mx01.intmail.prod.int.phx2.redhat.com [10.5.11.11]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id C23831005509; Sat, 4 Apr 2020 14:39:05 +0000 (UTC) Received: from kamzik.brq.redhat.com (unknown [10.40.192.30]) by smtp.corp.redhat.com (Postfix) with ESMTP id 039B69B912; Sat, 4 Apr 2020 14:38:55 +0000 (UTC) From: Andrew Jones To: pbonzini@redhat.com Cc: kvm@vger.kernel.org, kvmarm@lists.cs.columbia.edu, Eric Auger , Zenghui Yu Subject: [PULL kvm-unit-tests 30/39] arm/arm64: gicv3: Add some re-distributor defines Date: Sat, 4 Apr 2020 16:37:22 +0200 Message-Id: <20200404143731.208138-31-drjones@redhat.com> In-Reply-To: <20200404143731.208138-1-drjones@redhat.com> References: <20200404143731.208138-1-drjones@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.11 Sender: kvm-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: kvm@vger.kernel.org From: Eric Auger PROPBASER, PENDBASE and GICR_CTRL will be used for LPI management. Signed-off-by: Eric Auger Reviewed-by: Zenghui Yu Signed-off-by: Andrew Jones --- lib/arm/asm/gic-v3.h | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/lib/arm/asm/gic-v3.h b/lib/arm/asm/gic-v3.h index e2736a12b319..47df05159ac8 100644 --- a/lib/arm/asm/gic-v3.h +++ b/lib/arm/asm/gic-v3.h @@ -18,6 +18,7 @@ * We expect to be run in Non-secure mode, thus we define the * group1 enable bits with respect to that view. */ +#define GICD_CTLR 0x0000 #define GICD_CTLR_RWP (1U << 31) #define GICD_CTLR_ARE_NS (1U << 4) #define GICD_CTLR_ENABLE_G1A (1U << 1) @@ -38,6 +39,11 @@ #define GICR_ICACTIVER0 GICD_ICACTIVER #define GICR_IPRIORITYR0 GICD_IPRIORITYR +#define GICR_PROPBASER 0x0070 +#define GICR_PENDBASER 0x0078 +#define GICR_CTLR GICD_CTLR +#define GICR_CTLR_ENABLE_LPIS (1UL << 0) + #define ICC_SGI1R_AFFINITY_1_SHIFT 16 #define ICC_SGI1R_AFFINITY_2_SHIFT 32 #define ICC_SGI1R_AFFINITY_3_SHIFT 48 From patchwork Sat Apr 4 14:37:23 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Andrew Jones X-Patchwork-Id: 11474363 Return-Path: Received: from mail.kernel.org (pdx-korg-mail-1.web.codeaurora.org [172.30.200.123]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 65C321392 for ; Sat, 4 Apr 2020 14:39:15 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id 4485C2071C for ; Sat, 4 Apr 2020 14:39:15 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (1024-bit key) header.d=redhat.com header.i=@redhat.com header.b="N3TzlgM1" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726578AbgDDOjO (ORCPT ); Sat, 4 Apr 2020 10:39:14 -0400 Received: from us-smtp-1.mimecast.com ([205.139.110.61]:32119 "EHLO us-smtp-delivery-1.mimecast.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S1726327AbgDDOjO (ORCPT ); Sat, 4 Apr 2020 10:39:14 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1586011153; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=7fGTGQzCIxrbMDmqtQNR/h/1yu6q0TCsonXheaRiMmE=; b=N3TzlgM1pkfsnwWpNvLK/9rj094NLvrqe0bhGf1NODvVqVaWWX7DTyV/p1WwE46sjzb2+V 72KR8k8zfPNb9CIPEypQhLrT6VS0/roh+obDeRM6RziJ0rKPQol1E6NaJQ0Lif0oCr06va aoAn6/BfTz89pvdu+8l496lxbr03hp8= Received: from mimecast-mx01.redhat.com (mimecast-mx01.redhat.com [209.132.183.4]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-70-Yc7whLBXOOu3YIHAf9MWog-1; Sat, 04 Apr 2020 10:39:10 -0400 X-MC-Unique: Yc7whLBXOOu3YIHAf9MWog-1 Received: from smtp.corp.redhat.com (int-mx01.intmail.prod.int.phx2.redhat.com [10.5.11.11]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id 89FC98017F3; Sat, 4 Apr 2020 14:39:09 +0000 (UTC) Received: from kamzik.brq.redhat.com (unknown [10.40.192.30]) by smtp.corp.redhat.com (Postfix) with ESMTP id 793D29B912; Sat, 4 Apr 2020 14:39:05 +0000 (UTC) From: Andrew Jones To: pbonzini@redhat.com Cc: kvm@vger.kernel.org, kvmarm@lists.cs.columbia.edu, Eric Auger , Zenghui Yu Subject: [PULL kvm-unit-tests 31/39] arm/arm64: gicv3: Set the LPI config and pending tables Date: Sat, 4 Apr 2020 16:37:23 +0200 Message-Id: <20200404143731.208138-32-drjones@redhat.com> In-Reply-To: <20200404143731.208138-1-drjones@redhat.com> References: <20200404143731.208138-1-drjones@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.11 Sender: kvm-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: kvm@vger.kernel.org From: Eric Auger Allocate the LPI configuration and per re-distributor pending table. Set redistributor's PROPBASER and PENDBASER. The LPIs are enabled by default in the config table. Also introduce a helper routine that allows to set the pending table bit for a given LPI and macros to set/get its configuration. Signed-off-by: Eric Auger Reviewed-by: Zenghui Yu Signed-off-by: Andrew Jones --- lib/arm/asm/gic-v3.h | 17 ++++++++++++++ lib/arm/gic-v3.c | 53 ++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 70 insertions(+) diff --git a/lib/arm/asm/gic-v3.h b/lib/arm/asm/gic-v3.h index 47df05159ac8..fedffa8e0843 100644 --- a/lib/arm/asm/gic-v3.h +++ b/lib/arm/asm/gic-v3.h @@ -50,6 +50,13 @@ #define MPIDR_TO_SGI_AFFINITY(cluster_id, level) \ (MPIDR_AFFINITY_LEVEL(cluster_id, level) << ICC_SGI1R_AFFINITY_## level ## _SHIFT) +#define GICR_PENDBASER_PTZ BIT_ULL(62) + +#define LPI_PROP_GROUP1 (1 << 1) +#define LPI_PROP_ENABLED (1 << 0) +#define LPI_PROP_DEFAULT_PRIO 0xa0 +#define LPI_PROP_DEFAULT (LPI_PROP_DEFAULT_PRIO | LPI_PROP_GROUP1 | LPI_PROP_ENABLED) + #include #ifndef __ASSEMBLY__ @@ -66,6 +73,8 @@ struct gicv3_data { void *dist_base; void *redist_bases[GICV3_NR_REDISTS]; void *redist_base[NR_CPUS]; + u8 *lpi_prop; + void *lpi_pend[NR_CPUS]; unsigned int irq_nr; }; extern struct gicv3_data gicv3_data; @@ -82,6 +91,8 @@ extern void gicv3_write_eoir(u32 irqstat); extern void gicv3_ipi_send_single(int irq, int cpu); extern void gicv3_ipi_send_mask(int irq, const cpumask_t *dest); extern void gicv3_set_redist_base(size_t stride); +extern void gicv3_lpi_set_clr_pending(int rdist, int n, bool set); +extern void gicv3_lpi_alloc_tables(void); static inline void gicv3_do_wait_for_rwp(void *base) { @@ -127,5 +138,11 @@ static inline u64 mpidr_uncompress(u32 compressed) return mpidr; } +#define gicv3_lpi_set_config(intid, value) ({ \ + gicv3_data.lpi_prop[LPI_OFFSET(intid)] = value; \ +}) + +#define gicv3_lpi_get_config(intid) (gicv3_data.lpi_prop[LPI_OFFSET(intid)]) + #endif /* !__ASSEMBLY__ */ #endif /* _ASMARM_GIC_V3_H_ */ diff --git a/lib/arm/gic-v3.c b/lib/arm/gic-v3.c index feecb5e67caf..6cf1d1d27340 100644 --- a/lib/arm/gic-v3.c +++ b/lib/arm/gic-v3.c @@ -5,6 +5,7 @@ */ #include #include +#include void gicv3_set_redist_base(size_t stride) { @@ -147,3 +148,55 @@ void gicv3_ipi_send_single(int irq, int cpu) cpumask_set_cpu(cpu, &dest); gicv3_ipi_send_mask(irq, &dest); } + +#if defined(__aarch64__) + +/* + * alloc_lpi_tables - Allocate LPI config and pending tables + * and set PROPBASER (shared by all rdistributors) and per + * redistributor PENDBASER. + * + * gicv3_set_redist_base() must be called before + */ +void gicv3_lpi_alloc_tables(void) +{ + unsigned long n = SZ_64K >> PAGE_SHIFT; + unsigned long order = fls(n); + u64 prop_val; + int cpu; + + assert(gicv3_redist_base()); + + gicv3_data.lpi_prop = alloc_pages(order); + + /* ID bits = 13, ie. up to 14b LPI INTID */ + prop_val = (u64)(virt_to_phys(gicv3_data.lpi_prop)) | 13; + + for_each_present_cpu(cpu) { + u64 pend_val; + void *ptr; + + ptr = gicv3_data.redist_base[cpu]; + + writeq(prop_val, ptr + GICR_PROPBASER); + + gicv3_data.lpi_pend[cpu] = alloc_pages(order); + pend_val = (u64)(virt_to_phys(gicv3_data.lpi_pend[cpu])); + writeq(pend_val, ptr + GICR_PENDBASER); + } +} + +void gicv3_lpi_set_clr_pending(int rdist, int n, bool set) +{ + u8 *ptr = gicv3_data.lpi_pend[rdist]; + u8 mask = 1 << (n % 8), byte; + + ptr += (n / 8); + byte = *ptr; + if (set) + byte |= mask; + else + byte &= ~mask; + *ptr = byte; +} +#endif /* __aarch64__ */ From patchwork Sat Apr 4 14:37:24 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Andrew Jones X-Patchwork-Id: 11474365 Return-Path: Received: from mail.kernel.org (pdx-korg-mail-1.web.codeaurora.org [172.30.200.123]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 0B6201392 for ; Sat, 4 Apr 2020 14:39:18 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id CBBB8206F5 for ; Sat, 4 Apr 2020 14:39:17 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (1024-bit key) header.d=redhat.com header.i=@redhat.com header.b="OXC7KNRg" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726670AbgDDOjR (ORCPT ); Sat, 4 Apr 2020 10:39:17 -0400 Received: from us-smtp-1.mimecast.com ([207.211.31.81]:25083 "EHLO us-smtp-delivery-1.mimecast.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S1726327AbgDDOjQ (ORCPT ); Sat, 4 Apr 2020 10:39:16 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1586011155; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=X20dgf4X4pc8SyTqMUbSMQahZSITCPlh6jRxQWys+PQ=; b=OXC7KNRgzbrSdfQ3IUPWCyIjXH9E5DlUMeR8tJIhDcXpL8GXFACFYAwzRPFAn+KXPAqUJw 0Y8MpqwZDEjWKPjXs9sGhUFhxNc3j121n26LB4fgaoI+5fgBxYcJKwP0UpkA5droZ7w2xQ Qbo1aAf9+9ynZK61kcThpzJPc2nnW0A= Received: from mimecast-mx01.redhat.com (mimecast-mx01.redhat.com [209.132.183.4]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-507-0XoXD2ExO-WrYaVq5OezQw-1; Sat, 04 Apr 2020 10:39:13 -0400 X-MC-Unique: 0XoXD2ExO-WrYaVq5OezQw-1 Received: from smtp.corp.redhat.com (int-mx01.intmail.prod.int.phx2.redhat.com [10.5.11.11]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id 1F0A2800D53; Sat, 4 Apr 2020 14:39:12 +0000 (UTC) Received: from kamzik.brq.redhat.com (unknown [10.40.192.30]) by smtp.corp.redhat.com (Postfix) with ESMTP id 0DB3D1147D3; Sat, 4 Apr 2020 14:39:09 +0000 (UTC) From: Andrew Jones To: pbonzini@redhat.com Cc: kvm@vger.kernel.org, kvmarm@lists.cs.columbia.edu, Eric Auger , Zenghui Yu Subject: [PULL kvm-unit-tests 32/39] arm/arm64: ITS: Introspection tests Date: Sat, 4 Apr 2020 16:37:24 +0200 Message-Id: <20200404143731.208138-33-drjones@redhat.com> In-Reply-To: <20200404143731.208138-1-drjones@redhat.com> References: <20200404143731.208138-1-drjones@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.11 Sender: kvm-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: kvm@vger.kernel.org From: Eric Auger Detect the presence of an ITS as part of the GICv3 init routine, initialize its base address and read few registers the IIDR, the TYPER to store its dimensioning parameters. Parse the BASER registers. As part of the init sequence we also init all the requested tables. This is our first ITS test, belonging to a new "its" group. Signed-off-by: Eric Auger Reviewed-by: Zenghui Yu Signed-off-by: Andrew Jones --- arm/Makefile.arm64 | 1 + arm/gic.c | 48 +++++++++++++++++++ arm/unittests.cfg | 7 +++ lib/arm/asm/gic-v3-its.h | 27 +++++++++++ lib/arm/asm/gic.h | 1 + lib/arm/gic.c | 40 +++++++++++++--- lib/arm64/asm/gic-v3-its.h | 96 +++++++++++++++++++++++++++++++++++++ lib/arm64/gic-v3-its.c | 98 ++++++++++++++++++++++++++++++++++++++ 8 files changed, 311 insertions(+), 7 deletions(-) create mode 100644 lib/arm/asm/gic-v3-its.h create mode 100644 lib/arm64/asm/gic-v3-its.h create mode 100644 lib/arm64/gic-v3-its.c diff --git a/arm/Makefile.arm64 b/arm/Makefile.arm64 index 6d3dc2c4a464..60182ae92778 100644 --- a/arm/Makefile.arm64 +++ b/arm/Makefile.arm64 @@ -19,6 +19,7 @@ endef cstart.o = $(TEST_DIR)/cstart64.o cflatobjs += lib/arm64/processor.o cflatobjs += lib/arm64/spinlock.o +cflatobjs += lib/arm64/gic-v3-its.o OBJDIRS += lib/arm64 diff --git a/arm/gic.c b/arm/gic.c index 2f904b0ef375..649ed81d33e1 100644 --- a/arm/gic.c +++ b/arm/gic.c @@ -16,6 +16,7 @@ #include #include #include +#include #include #include #include @@ -517,6 +518,49 @@ static void gic_test_mmio(void) test_targets(nr_irqs); } +#if defined(__arm__) + +static void test_its_introspection(void) {} + +#else /* __aarch64__ */ + +static void test_its_introspection(void) +{ + struct its_baser *dev_baser = &its_data.device_baser; + struct its_baser *coll_baser = &its_data.coll_baser; + struct its_typer *typer = &its_data.typer; + + if (!gicv3_its_base()) { + report_skip("No ITS, skip ..."); + return; + } + + /* IIDR */ + report(test_readonly_32(gicv3_its_base() + GITS_IIDR, false), + "GITS_IIDR is read-only"), + + /* TYPER */ + report(test_readonly_32(gicv3_its_base() + GITS_TYPER, false), + "GITS_TYPER is read-only"); + + report(typer->phys_lpi, "ITS supports physical LPIs"); + report_info("vLPI support: %s", typer->virt_lpi ? "yes" : "no"); + report_info("ITT entry size = 0x%x", typer->ite_size); + report_info("Bit Count: EventID=%d DeviceId=%d CollId=%d", + typer->eventid_bits, typer->deviceid_bits, + typer->collid_bits); + report(typer->eventid_bits && typer->deviceid_bits && + typer->collid_bits, "ID spaces"); + report_info("Target address format %s", + typer->pta ? "Redist base address" : "PE #"); + + report(dev_baser && coll_baser, "detect device and collection BASER"); + report_info("device table entry_size = 0x%x", dev_baser->esz); + report_info("collection table entry_size = 0x%x", coll_baser->esz); +} + +#endif + int main(int argc, char **argv) { if (!gic_init()) { @@ -548,6 +592,10 @@ int main(int argc, char **argv) report_prefix_push(argv[1]); gic_test_mmio(); report_prefix_pop(); + } else if (strcmp(argv[1], "its-introspection") == 0) { + report_prefix_push(argv[1]); + test_its_introspection(); + report_prefix_pop(); } else { report_abort("Unknown subtest '%s'", argv[1]); } diff --git a/arm/unittests.cfg b/arm/unittests.cfg index 455fd10d63c9..fff37f9fb5e6 100644 --- a/arm/unittests.cfg +++ b/arm/unittests.cfg @@ -177,6 +177,13 @@ smp = $MAX_SMP extra_params = -machine gic-version=3 -append 'active' groups = gic +[its-introspection] +file = gic.flat +smp = $MAX_SMP +extra_params = -machine gic-version=3 -append 'its-introspection' +groups = its +arch = arm64 + # Test PSCI emulation [psci] file = psci.flat diff --git a/lib/arm/asm/gic-v3-its.h b/lib/arm/asm/gic-v3-its.h new file mode 100644 index 000000000000..efd8f675dbf2 --- /dev/null +++ b/lib/arm/asm/gic-v3-its.h @@ -0,0 +1,27 @@ +/* + * ITS 32-bit stubs + * + * Copyright (C) 2020, Red Hat Inc, Eric Auger + * + * This work is licensed under the terms of the GNU LGPL, version 2. + */ +#ifndef _ASMARM_GIC_V3_ITS_H_ +#define _ASMARM_GIC_V3_ITS_H_ + +#ifndef _ASMARM_GIC_H_ +#error Do not directly include . Include +#endif + +#include + +/* dummy its_data struct to allow gic_get_dt_bases() call */ +struct its_data { + void *base; +}; + +static inline void its_init(void) +{ + assert_msg(false, "not supported on 32-bit"); +} + +#endif /* _ASMARM_GIC_V3_ITS_H_ */ diff --git a/lib/arm/asm/gic.h b/lib/arm/asm/gic.h index afb33096078d..38e79b2ac281 100644 --- a/lib/arm/asm/gic.h +++ b/lib/arm/asm/gic.h @@ -40,6 +40,7 @@ #include #include +#include #define PPI(irq) ((irq) + 16) #define SPI(irq) ((irq) + GIC_FIRST_SPI) diff --git a/lib/arm/gic.c b/lib/arm/gic.c index 8a1a8c84bf29..1bfcfcfbc253 100644 --- a/lib/arm/gic.c +++ b/lib/arm/gic.c @@ -9,6 +9,7 @@ struct gicv2_data gicv2_data; struct gicv3_data gicv3_data; +struct its_data its_data; struct gic_common_ops { void (*enable_defaults)(void); @@ -44,12 +45,13 @@ static const struct gic_common_ops gicv3_common_ops = { * Documentation/devicetree/bindings/interrupt-controller/arm,gic-v3.txt */ static bool -gic_get_dt_bases(const char *compatible, void **base1, void **base2) +gic_get_dt_bases(const char *compatible, void **base1, void **base2, void **base3) { struct dt_pbus_reg reg; - struct dt_device gic; + struct dt_device gic, its; struct dt_bus bus; - int node, ret, i; + int node, subnode, ret, i, len; + const void *fdt = dt_fdt(); dt_bus_init_defaults(&bus); dt_device_init(&gic, &bus, NULL); @@ -74,19 +76,39 @@ gic_get_dt_bases(const char *compatible, void **base1, void **base2) base2[i] = ioremap(reg.addr, reg.size); } + if (!base3) { + assert(!strcmp(compatible, "arm,cortex-a15-gic")); + return true; + } + + assert(!strcmp(compatible, "arm,gic-v3")); + + dt_for_each_subnode(node, subnode) { + const struct fdt_property *prop; + + prop = fdt_get_property(fdt, subnode, "compatible", &len); + if (!strcmp((char *)prop->data, "arm,gic-v3-its")) { + dt_device_bind_node(&its, subnode); + ret = dt_pbus_translate(&its, 0, ®); + assert(ret == 0); + *base3 = ioremap(reg.addr, reg.size); + break; + } + } + return true; } int gicv2_init(void) { return gic_get_dt_bases("arm,cortex-a15-gic", - &gicv2_data.dist_base, &gicv2_data.cpu_base); + &gicv2_data.dist_base, &gicv2_data.cpu_base, NULL); } int gicv3_init(void) { return gic_get_dt_bases("arm,gic-v3", &gicv3_data.dist_base, - &gicv3_data.redist_bases[0]); + &gicv3_data.redist_bases[0], &its_data.base); } int gic_version(void) @@ -100,10 +122,14 @@ int gic_version(void) int gic_init(void) { - if (gicv2_init()) + if (gicv2_init()) { gic_common_ops = &gicv2_common_ops; - else if (gicv3_init()) + } else if (gicv3_init()) { gic_common_ops = &gicv3_common_ops; +#ifdef __aarch64__ + its_init(); +#endif + } return gic_version(); } diff --git a/lib/arm64/asm/gic-v3-its.h b/lib/arm64/asm/gic-v3-its.h new file mode 100644 index 000000000000..c0bd58c6d0f5 --- /dev/null +++ b/lib/arm64/asm/gic-v3-its.h @@ -0,0 +1,96 @@ +/* + * All ITS* defines are lifted from include/linux/irqchip/arm-gic-v3.h + * + * Copyright (C) 2020, Red Hat Inc, Eric Auger + * + * This work is licensed under the terms of the GNU LGPL, version 2. + */ +#ifndef _ASMARM64_GIC_V3_ITS_H_ +#define _ASMARM64_GIC_V3_ITS_H_ + +#ifndef _ASMARM_GIC_H_ +#error Do not directly include . Include +#endif + +struct its_typer { + unsigned int ite_size; + unsigned int eventid_bits; + unsigned int deviceid_bits; + unsigned int collid_bits; + bool pta; + bool phys_lpi; + bool virt_lpi; +}; + +struct its_baser { + int index; + size_t psz; + int esz; + bool indirect; + void *table_addr; +}; + +#define GITS_BASER_NR_REGS 8 + +struct its_data { + void *base; + struct its_typer typer; + struct its_baser device_baser; + struct its_baser coll_baser; + struct its_cmd_block *cmd_base; + struct its_cmd_block *cmd_write; +}; + +extern struct its_data its_data; + +#define gicv3_its_base() (its_data.base) + +#define GITS_CTLR 0x0000 +#define GITS_IIDR 0x0004 +#define GITS_TYPER 0x0008 +#define GITS_CBASER 0x0080 +#define GITS_CWRITER 0x0088 +#define GITS_CREADR 0x0090 +#define GITS_BASER 0x0100 + +#define GITS_TYPER_PLPIS BIT(0) +#define GITS_TYPER_VLPIS BIT(1) +#define GITS_TYPER_ITT_ENTRY_SIZE GENMASK_ULL(7, 4) +#define GITS_TYPER_ITT_ENTRY_SIZE_SHIFT 4 +#define GITS_TYPER_IDBITS GENMASK_ULL(12, 8) +#define GITS_TYPER_IDBITS_SHIFT 8 +#define GITS_TYPER_DEVBITS GENMASK_ULL(17, 13) +#define GITS_TYPER_DEVBITS_SHIFT 13 +#define GITS_TYPER_PTA BIT(19) +#define GITS_TYPER_CIDBITS GENMASK_ULL(35, 32) +#define GITS_TYPER_CIDBITS_SHIFT 32 +#define GITS_TYPER_CIL BIT(36) + +#define GITS_CTLR_ENABLE (1U << 0) + +#define GITS_CBASER_VALID (1UL << 63) + +#define GITS_BASER_VALID BIT(63) +#define GITS_BASER_INDIRECT BIT(62) +#define GITS_BASER_TYPE_SHIFT (56) +#define GITS_BASER_TYPE(r) (((r) >> GITS_BASER_TYPE_SHIFT) & 7) +#define GITS_BASER_ENTRY_SIZE_SHIFT (48) +#define GITS_BASER_ENTRY_SIZE(r) ((((r) >> GITS_BASER_ENTRY_SIZE_SHIFT) & 0x1f) + 1) +#define GITS_BASER_PAGE_SIZE_SHIFT (8) +#define GITS_BASER_PAGE_SIZE_4K (0UL << GITS_BASER_PAGE_SIZE_SHIFT) +#define GITS_BASER_PAGE_SIZE_16K (1UL << GITS_BASER_PAGE_SIZE_SHIFT) +#define GITS_BASER_PAGE_SIZE_64K (2UL << GITS_BASER_PAGE_SIZE_SHIFT) +#define GITS_BASER_PAGE_SIZE_MASK (3UL << GITS_BASER_PAGE_SIZE_SHIFT) +#define GITS_BASER_PAGES_MAX 256 +#define GITS_BASER_PAGES_SHIFT (0) +#define GITS_BASER_NR_PAGES(r) (((r) & 0xff) + 1) +#define GITS_BASER_PHYS_ADDR_MASK 0xFFFFFFFFF000 +#define GITS_BASER_TYPE_NONE 0 +#define GITS_BASER_TYPE_DEVICE 1 +#define GITS_BASER_TYPE_COLLECTION 4 + +extern void its_parse_typer(void); +extern void its_init(void); +extern int its_baser_lookup(int i, struct its_baser *baser); + +#endif /* _ASMARM64_GIC_V3_ITS_H_ */ diff --git a/lib/arm64/gic-v3-its.c b/lib/arm64/gic-v3-its.c new file mode 100644 index 000000000000..04dde9774c5d --- /dev/null +++ b/lib/arm64/gic-v3-its.c @@ -0,0 +1,98 @@ +/* + * Copyright (C) 2020, Red Hat Inc, Eric Auger + * + * This work is licensed under the terms of the GNU LGPL, version 2. + */ +#include +#include + +void its_parse_typer(void) +{ + u64 typer = readq(gicv3_its_base() + GITS_TYPER); + struct its_typer *t = &its_data.typer; + + t->ite_size = ((typer & GITS_TYPER_ITT_ENTRY_SIZE) >> GITS_TYPER_ITT_ENTRY_SIZE_SHIFT) + 1; + t->pta = typer & GITS_TYPER_PTA; + t->eventid_bits = ((typer & GITS_TYPER_IDBITS) >> GITS_TYPER_IDBITS_SHIFT) + 1; + t->deviceid_bits = ((typer & GITS_TYPER_DEVBITS) >> GITS_TYPER_DEVBITS_SHIFT) + 1; + + if (typer & GITS_TYPER_CIL) + t->collid_bits = ((typer & GITS_TYPER_CIDBITS) >> GITS_TYPER_CIDBITS_SHIFT) + 1; + else + t->collid_bits = 16; + + t->virt_lpi = typer & GITS_TYPER_VLPIS; + t->phys_lpi = typer & GITS_TYPER_PLPIS; +} + +int its_baser_lookup(int type, struct its_baser *baser) +{ + int i; + + for (i = 0; i < GITS_BASER_NR_REGS; i++) { + void *reg_addr = gicv3_its_base() + GITS_BASER + i * 8; + u64 val = readq(reg_addr); + + if (GITS_BASER_TYPE(val) == type) { + assert((val & GITS_BASER_PAGE_SIZE_MASK) == GITS_BASER_PAGE_SIZE_64K); + baser->esz = GITS_BASER_ENTRY_SIZE(val); + baser->indirect = val & GITS_BASER_INDIRECT; + baser->index = i; + return 0; + } + } + return -1; +} + +/* + * Allocate the BASER table (a single page of size @baser->psz) + * and set the BASER valid + */ +static void its_baser_alloc_table(struct its_baser *baser, size_t size) +{ + unsigned long order = get_order(size >> PAGE_SHIFT); + void *reg_addr = gicv3_its_base() + GITS_BASER + baser->index * 8; + u64 val = readq(reg_addr); + + baser->table_addr = alloc_pages(order); + + val |= virt_to_phys(baser->table_addr) | GITS_BASER_VALID; + + writeq(val, reg_addr); +} + +/* + * init_cmd_queue - Allocate the command queue and initialize + * CBASER, CWRITER + */ +static void its_cmd_queue_init(void) +{ + unsigned long order = get_order(SZ_64K >> PAGE_SHIFT); + u64 cbaser; + + its_data.cmd_base = alloc_pages(order); + + cbaser = virt_to_phys(its_data.cmd_base) | (SZ_64K / SZ_4K - 1) | GITS_CBASER_VALID; + + writeq(cbaser, its_data.base + GITS_CBASER); + + its_data.cmd_write = its_data.cmd_base; + writeq(0, its_data.base + GITS_CWRITER); +} + +void its_init(void) +{ + if (!its_data.base) + return; + + its_parse_typer(); + + assert(!its_baser_lookup(GITS_BASER_TYPE_DEVICE, &its_data.device_baser)); + assert(!its_baser_lookup(GITS_BASER_TYPE_COLLECTION, &its_data.coll_baser)); + + its_baser_alloc_table(&its_data.device_baser, SZ_64K); + its_baser_alloc_table(&its_data.coll_baser, SZ_64K); + + its_cmd_queue_init(); +} + From patchwork Sat Apr 4 14:37:25 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Andrew Jones X-Patchwork-Id: 11474367 Return-Path: Received: from mail.kernel.org (pdx-korg-mail-1.web.codeaurora.org [172.30.200.123]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id BA596912 for ; Sat, 4 Apr 2020 14:39:21 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id 99D3B2071C for ; Sat, 4 Apr 2020 14:39:21 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (1024-bit key) header.d=redhat.com header.i=@redhat.com header.b="bDm5UL7t" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726679AbgDDOjU (ORCPT ); Sat, 4 Apr 2020 10:39:20 -0400 Received: from us-smtp-1.mimecast.com ([207.211.31.81]:21905 "EHLO us-smtp-delivery-1.mimecast.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S1726397AbgDDOjU (ORCPT ); Sat, 4 Apr 2020 10:39:20 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1586011159; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=3WNP/h3pvTehY/zddj/d3JMMeG0kwDSFb6yKr4zYYro=; b=bDm5UL7t5IZ5xuAVkhhPCNV6gWTZ9C+zgsNwnJteXhPnEvOZ9sZjlbSx2cIKHUSH4S3SxA pqqBovJKd/HS5L+tH4TjlnNQ7iHmESfeYKg23hckQFKq9QL3ymxgmkNJ+evCnV/4esirFM BXc+6inA3YhlSHF2kJInJIETeYqrzH8= Received: from mimecast-mx01.redhat.com (mimecast-mx01.redhat.com [209.132.183.4]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-59-ZLf5PJFaOuG71inIxMaDaw-1; Sat, 04 Apr 2020 10:39:17 -0400 X-MC-Unique: ZLf5PJFaOuG71inIxMaDaw-1 Received: from smtp.corp.redhat.com (int-mx01.intmail.prod.int.phx2.redhat.com [10.5.11.11]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id B086B8017CE; Sat, 4 Apr 2020 14:39:16 +0000 (UTC) Received: from kamzik.brq.redhat.com (unknown [10.40.192.30]) by smtp.corp.redhat.com (Postfix) with ESMTP id A22971147D3; Sat, 4 Apr 2020 14:39:12 +0000 (UTC) From: Andrew Jones To: pbonzini@redhat.com Cc: kvm@vger.kernel.org, kvmarm@lists.cs.columbia.edu, Eric Auger , Zenghui Yu Subject: [PULL kvm-unit-tests 33/39] arm/arm64: ITS: its_enable_defaults Date: Sat, 4 Apr 2020 16:37:25 +0200 Message-Id: <20200404143731.208138-34-drjones@redhat.com> In-Reply-To: <20200404143731.208138-1-drjones@redhat.com> References: <20200404143731.208138-1-drjones@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.11 Sender: kvm-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: kvm@vger.kernel.org From: Eric Auger its_enable_defaults() enable LPIs at redistributor level and ITS level. gicv3_enable_defaults must be called before. Signed-off-by: Eric Auger Reviewed-by: Zenghui Yu Signed-off-by: Andrew Jones --- lib/arm/asm/gic-v3.h | 6 ++++++ lib/arm/gic-v3.c | 25 +++++++++++++++++++++++++ lib/arm64/asm/gic-v3-its.h | 1 + lib/arm64/gic-v3-its.c | 13 +++++++++++++ 4 files changed, 45 insertions(+) diff --git a/lib/arm/asm/gic-v3.h b/lib/arm/asm/gic-v3.h index fedffa8e0843..cb72922662be 100644 --- a/lib/arm/asm/gic-v3.h +++ b/lib/arm/asm/gic-v3.h @@ -57,6 +57,10 @@ #define LPI_PROP_DEFAULT_PRIO 0xa0 #define LPI_PROP_DEFAULT (LPI_PROP_DEFAULT_PRIO | LPI_PROP_GROUP1 | LPI_PROP_ENABLED) +#define LPI_ID_BASE 8192 +#define LPI(lpi) ((lpi) + LPI_ID_BASE) +#define LPI_OFFSET(intid) ((intid) - LPI_ID_BASE) + #include #ifndef __ASSEMBLY__ @@ -93,6 +97,8 @@ extern void gicv3_ipi_send_mask(int irq, const cpumask_t *dest); extern void gicv3_set_redist_base(size_t stride); extern void gicv3_lpi_set_clr_pending(int rdist, int n, bool set); extern void gicv3_lpi_alloc_tables(void); +extern void gicv3_lpi_rdist_enable(int redist); +extern void gicv3_lpi_rdist_disable(int redist); static inline void gicv3_do_wait_for_rwp(void *base) { diff --git a/lib/arm/gic-v3.c b/lib/arm/gic-v3.c index 6cf1d1d27340..a7e2cb819746 100644 --- a/lib/arm/gic-v3.c +++ b/lib/arm/gic-v3.c @@ -199,4 +199,29 @@ void gicv3_lpi_set_clr_pending(int rdist, int n, bool set) byte &= ~mask; *ptr = byte; } + +static void gicv3_lpi_rdist_ctrl(u32 redist, bool set) +{ + void *ptr; + u64 val; + + assert(redist < nr_cpus); + + ptr = gicv3_data.redist_base[redist]; + val = readl(ptr + GICR_CTLR); + if (set) + val |= GICR_CTLR_ENABLE_LPIS; + else + val &= ~GICR_CTLR_ENABLE_LPIS; + writel(val, ptr + GICR_CTLR); +} + +void gicv3_lpi_rdist_enable(int redist) +{ + gicv3_lpi_rdist_ctrl(redist, true); +} +void gicv3_lpi_rdist_disable(int redist) +{ + gicv3_lpi_rdist_ctrl(redist, false); +} #endif /* __aarch64__ */ diff --git a/lib/arm64/asm/gic-v3-its.h b/lib/arm64/asm/gic-v3-its.h index c0bd58c6d0f5..7e03e4ce2b17 100644 --- a/lib/arm64/asm/gic-v3-its.h +++ b/lib/arm64/asm/gic-v3-its.h @@ -92,5 +92,6 @@ extern struct its_data its_data; extern void its_parse_typer(void); extern void its_init(void); extern int its_baser_lookup(int i, struct its_baser *baser); +extern void its_enable_defaults(void); #endif /* _ASMARM64_GIC_V3_ITS_H_ */ diff --git a/lib/arm64/gic-v3-its.c b/lib/arm64/gic-v3-its.c index 04dde9774c5d..cf176b74a277 100644 --- a/lib/arm64/gic-v3-its.c +++ b/lib/arm64/gic-v3-its.c @@ -96,3 +96,16 @@ void its_init(void) its_cmd_queue_init(); } +/* must be called after gicv3_enable_defaults */ +void its_enable_defaults(void) +{ + int cpu; + + /* Allocate LPI config and pending tables */ + gicv3_lpi_alloc_tables(); + + for_each_present_cpu(cpu) + gicv3_lpi_rdist_enable(cpu); + + writel(GITS_CTLR_ENABLE, its_data.base + GITS_CTLR); +} From patchwork Sat Apr 4 14:37:26 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Andrew Jones X-Patchwork-Id: 11474369 Return-Path: Received: from mail.kernel.org (pdx-korg-mail-1.web.codeaurora.org [172.30.200.123]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 63A1F1392 for ; Sat, 4 Apr 2020 14:39:27 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id 427F32070E for ; Sat, 4 Apr 2020 14:39:27 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (1024-bit key) header.d=redhat.com header.i=@redhat.com header.b="MR3ADrAt" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726691AbgDDOj0 (ORCPT ); Sat, 4 Apr 2020 10:39:26 -0400 Received: from us-smtp-2.mimecast.com ([205.139.110.61]:41584 "EHLO us-smtp-delivery-1.mimecast.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S1726684AbgDDOj0 (ORCPT ); Sat, 4 Apr 2020 10:39:26 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1586011165; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=AEz5troQ6ynHVc5o8x3G+52JS9FvzhU5HuoUMu7WhdU=; b=MR3ADrAtK+xXqqFHZ2F3X4OuohkvUdDFRAS6f8emX6u7/LRmqfXqmW+dk5JEeE2X4aF+Nn ckBpG4oMFwK7RjJPZOwSphnqq2FtSEpoYLrFg2y/6nvDkdVKwZOHF8UQWS3ukANgzKYTfr f6FevnqYCX2S6kgOZ6LtUR/9sKNQ13E= Received: from mimecast-mx01.redhat.com (mimecast-mx01.redhat.com [209.132.183.4]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-74-YhXihnf-PdCSPhTOdbv3gA-1; Sat, 04 Apr 2020 10:39:22 -0400 X-MC-Unique: YhXihnf-PdCSPhTOdbv3gA-1 Received: from smtp.corp.redhat.com (int-mx01.intmail.prod.int.phx2.redhat.com [10.5.11.11]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id D54AF18AB2C5; Sat, 4 Apr 2020 14:39:21 +0000 (UTC) Received: from kamzik.brq.redhat.com (unknown [10.40.192.30]) by smtp.corp.redhat.com (Postfix) with ESMTP id 356C99B912; Sat, 4 Apr 2020 14:39:17 +0000 (UTC) From: Andrew Jones To: pbonzini@redhat.com Cc: kvm@vger.kernel.org, kvmarm@lists.cs.columbia.edu, Eric Auger , Zenghui Yu Subject: [PULL kvm-unit-tests 34/39] arm/arm64: ITS: Device and collection Initialization Date: Sat, 4 Apr 2020 16:37:26 +0200 Message-Id: <20200404143731.208138-35-drjones@redhat.com> In-Reply-To: <20200404143731.208138-1-drjones@redhat.com> References: <20200404143731.208138-1-drjones@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.11 Sender: kvm-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: kvm@vger.kernel.org From: Eric Auger Introduce an helper functions to register - a new device, characterized by its device id and the max number of event IDs that dimension its ITT (Interrupt Translation Table). The function allocates the ITT. - a new collection, characterized by its ID and the target processing engine (PE). Signed-off-by: Eric Auger Reviewed-by: Zenghui Yu Signed-off-by: Andrew Jones --- lib/arm64/asm/gic-v3-its.h | 19 +++++++++++++++++++ lib/arm64/gic-v3-its.c | 38 ++++++++++++++++++++++++++++++++++++++ 2 files changed, 57 insertions(+) diff --git a/lib/arm64/asm/gic-v3-its.h b/lib/arm64/asm/gic-v3-its.h index 7e03e4ce2b17..628eedf9f8ed 100644 --- a/lib/arm64/asm/gic-v3-its.h +++ b/lib/arm64/asm/gic-v3-its.h @@ -31,6 +31,19 @@ struct its_baser { }; #define GITS_BASER_NR_REGS 8 +#define GITS_MAX_DEVICES 8 +#define GITS_MAX_COLLECTIONS 8 + +struct its_device { + u32 device_id; /* device ID */ + u32 nr_ites; /* Max Interrupt Translation Entries */ + void *itt; /* Interrupt Translation Table GVA */ +}; + +struct its_collection { + u64 target_address; + u16 col_id; +}; struct its_data { void *base; @@ -39,6 +52,10 @@ struct its_data { struct its_baser coll_baser; struct its_cmd_block *cmd_base; struct its_cmd_block *cmd_write; + struct its_device devices[GITS_MAX_DEVICES]; + u32 nr_devices; /* Allocated Devices */ + struct its_collection collections[GITS_MAX_COLLECTIONS]; + u16 nr_collections; /* Allocated Collections */ }; extern struct its_data its_data; @@ -93,5 +110,7 @@ extern void its_parse_typer(void); extern void its_init(void); extern int its_baser_lookup(int i, struct its_baser *baser); extern void its_enable_defaults(void); +extern struct its_device *its_create_device(u32 dev_id, int nr_ites); +extern struct its_collection *its_create_collection(u16 col_id, u32 target_pe); #endif /* _ASMARM64_GIC_V3_ITS_H_ */ diff --git a/lib/arm64/gic-v3-its.c b/lib/arm64/gic-v3-its.c index cf176b74a277..ca91c3dd1108 100644 --- a/lib/arm64/gic-v3-its.c +++ b/lib/arm64/gic-v3-its.c @@ -109,3 +109,41 @@ void its_enable_defaults(void) writel(GITS_CTLR_ENABLE, its_data.base + GITS_CTLR); } + +struct its_device *its_create_device(u32 device_id, int nr_ites) +{ + struct its_device *new; + unsigned long n; + + assert(its_data.nr_devices < GITS_MAX_DEVICES); + + new = &its_data.devices[its_data.nr_devices]; + + new->device_id = device_id; + new->nr_ites = nr_ites; + + n = (its_data.typer.ite_size * nr_ites) >> PAGE_SHIFT; + new->itt = alloc_pages(get_order(n)); + + its_data.nr_devices++; + return new; +} + +struct its_collection *its_create_collection(u16 col_id, u32 pe) +{ + struct its_collection *new; + + assert(its_data.nr_collections < GITS_MAX_COLLECTIONS); + + new = &its_data.collections[its_data.nr_collections]; + + new->col_id = col_id; + + if (its_data.typer.pta) + new->target_address = (u64)gicv3_data.redist_base[pe]; + else + new->target_address = pe << 16; + + its_data.nr_collections++; + return new; +} From patchwork Sat Apr 4 14:37:27 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Andrew Jones X-Patchwork-Id: 11474373 Return-Path: Received: from mail.kernel.org (pdx-korg-mail-1.web.codeaurora.org [172.30.200.123]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id AFBD2912 for ; Sat, 4 Apr 2020 14:39:35 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id 7BD592070E for ; Sat, 4 Apr 2020 14:39:35 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (1024-bit key) header.d=redhat.com header.i=@redhat.com header.b="EtETW1QM" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726699AbgDDOje (ORCPT ); Sat, 4 Apr 2020 10:39:34 -0400 Received: from us-smtp-delivery-1.mimecast.com ([205.139.110.120]:23353 "EHLO us-smtp-1.mimecast.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S1726683AbgDDOje (ORCPT ); Sat, 4 Apr 2020 10:39:34 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1586011172; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=ZRN91yACq5PqA8SJ/Y8kUg+TyQDNP1bXBxAyZfJV0D0=; b=EtETW1QMaBrI2AI7HlsU+Ysxfj1MgrV66zVFu/oqiq8ygNU84dO6lGLoQrm3BHvd6elLKZ PXlMC2X6KCRbqZEp1LZUPslVBQsu/f8W3/kwpejkn2tcIEgEElSDic82CMRF3DPKwkaqHV KZB8EA3KMBNn/kQr2tU6kGLE0vqWnp8= Received: from mimecast-mx01.redhat.com (mimecast-mx01.redhat.com [209.132.183.4]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-418-VZzGuZSfOsq0nwOWbjYs-w-1; Sat, 04 Apr 2020 10:39:25 -0400 X-MC-Unique: VZzGuZSfOsq0nwOWbjYs-w-1 Received: from smtp.corp.redhat.com (int-mx01.intmail.prod.int.phx2.redhat.com [10.5.11.11]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id 52E51800D4E; Sat, 4 Apr 2020 14:39:24 +0000 (UTC) Received: from kamzik.brq.redhat.com (unknown [10.40.192.30]) by smtp.corp.redhat.com (Postfix) with ESMTP id 58F3F9B912; Sat, 4 Apr 2020 14:39:22 +0000 (UTC) From: Andrew Jones To: pbonzini@redhat.com Cc: kvm@vger.kernel.org, kvmarm@lists.cs.columbia.edu, Eric Auger , Zenghui Yu Subject: [PULL kvm-unit-tests 35/39] arm/arm64: ITS: Commands Date: Sat, 4 Apr 2020 16:37:27 +0200 Message-Id: <20200404143731.208138-36-drjones@redhat.com> In-Reply-To: <20200404143731.208138-1-drjones@redhat.com> References: <20200404143731.208138-1-drjones@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.11 Sender: kvm-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: kvm@vger.kernel.org From: Eric Auger Implement main ITS commands. The code is largely inherited from the ITS driver. Signed-off-by: Eric Auger Reviewed-by: Zenghui Yu Signed-off-by: Andrew Jones --- arm/Makefile.arm64 | 2 +- lib/arm64/asm/gic-v3-its.h | 55 +++++ lib/arm64/gic-v3-its-cmd.c | 459 +++++++++++++++++++++++++++++++++++++ 3 files changed, 515 insertions(+), 1 deletion(-) create mode 100644 lib/arm64/gic-v3-its-cmd.c diff --git a/arm/Makefile.arm64 b/arm/Makefile.arm64 index 60182ae92778..dfd0c56fe8fb 100644 --- a/arm/Makefile.arm64 +++ b/arm/Makefile.arm64 @@ -19,7 +19,7 @@ endef cstart.o = $(TEST_DIR)/cstart64.o cflatobjs += lib/arm64/processor.o cflatobjs += lib/arm64/spinlock.o -cflatobjs += lib/arm64/gic-v3-its.o +cflatobjs += lib/arm64/gic-v3-its.o lib/arm64/gic-v3-its-cmd.o OBJDIRS += lib/arm64 diff --git a/lib/arm64/asm/gic-v3-its.h b/lib/arm64/asm/gic-v3-its.h index 628eedf9f8ed..c203293a7838 100644 --- a/lib/arm64/asm/gic-v3-its.h +++ b/lib/arm64/asm/gic-v3-its.h @@ -106,6 +106,26 @@ extern struct its_data its_data; #define GITS_BASER_TYPE_DEVICE 1 #define GITS_BASER_TYPE_COLLECTION 4 +/* + * ITS commands + */ +#define GITS_CMD_MAPD 0x08 +#define GITS_CMD_MAPC 0x09 +#define GITS_CMD_MAPTI 0x0a +#define GITS_CMD_MAPI 0x0b +#define GITS_CMD_MOVI 0x01 +#define GITS_CMD_DISCARD 0x0f +#define GITS_CMD_INV 0x0c +#define GITS_CMD_MOVALL 0x0e +#define GITS_CMD_INVALL 0x0d +#define GITS_CMD_INT 0x03 +#define GITS_CMD_CLEAR 0x04 +#define GITS_CMD_SYNC 0x05 + +struct its_cmd_block { + u64 raw_cmd[4]; +}; + extern void its_parse_typer(void); extern void its_init(void); extern int its_baser_lookup(int i, struct its_baser *baser); @@ -113,4 +133,39 @@ extern void its_enable_defaults(void); extern struct its_device *its_create_device(u32 dev_id, int nr_ites); extern struct its_collection *its_create_collection(u16 col_id, u32 target_pe); +extern void __its_send_mapd(struct its_device *dev, int valid, bool verbose); +extern void __its_send_mapc(struct its_collection *col, int valid, bool verbose); +extern void __its_send_mapti(struct its_device *dev, u32 irq_id, u32 event_id, + struct its_collection *col, bool verbose); +extern void __its_send_int(struct its_device *dev, u32 event_id, bool verbose); +extern void __its_send_inv(struct its_device *dev, u32 event_id, bool verbose); +extern void __its_send_discard(struct its_device *dev, u32 event_id, bool verbose); +extern void __its_send_clear(struct its_device *dev, u32 event_id, bool verbose); +extern void __its_send_invall(struct its_collection *col, bool verbose); +extern void __its_send_movi(struct its_device *dev, struct its_collection *col, + u32 id, bool verbose); +extern void __its_send_sync(struct its_collection *col, bool verbose); + +#define its_send_mapd(dev, valid) __its_send_mapd(dev, valid, true) +#define its_send_mapc(col, valid) __its_send_mapc(col, valid, true) +#define its_send_mapti(dev, irqid, eventid, col) __its_send_mapti(dev, irqid, eventid, col, true) +#define its_send_int(dev, eventid) __its_send_int(dev, eventid, true) +#define its_send_inv(dev, eventid) __its_send_inv(dev, eventid, true) +#define its_send_discard(dev, eventid) __its_send_discard(dev, eventid, true) +#define its_send_clear(dev, eventid) __its_send_clear(dev, eventid, true) +#define its_send_invall(col) __its_send_invall(col, true) +#define its_send_movi(dev, col, id) __its_send_movi(dev, col, id, true) +#define its_send_sync(col) __its_send_sync(col, true) + +#define its_send_mapd_nv(dev, valid) __its_send_mapd(dev, valid, false) +#define its_send_mapc_nv(col, valid) __its_send_mapc(col, valid, false) +#define its_send_mapti_nv(dev, irqid, eventid, col) __its_send_mapti(dev, irqid, eventid, col, false) +#define its_send_int_nv(dev, eventid) __its_send_int(dev, eventid, false) +#define its_send_inv_nv(dev, eventid) __its_send_inv(dev, eventid, false) +#define its_send_discard_nv(dev, eventid) __its_send_discard(dev, eventid, false) +#define its_send_clear_nv(dev, eventid) __its_send_clear(dev, eventidn false) +#define its_send_invall_nv(col) __its_send_invall(col, false) +#define its_send_movi_nv(dev, col, id) __its_send_movi(dev, col, id, false) +#define its_send_sync_nv(col) __its_send_sync(col, false) + #endif /* _ASMARM64_GIC_V3_ITS_H_ */ diff --git a/lib/arm64/gic-v3-its-cmd.c b/lib/arm64/gic-v3-its-cmd.c new file mode 100644 index 000000000000..2c208d135d45 --- /dev/null +++ b/lib/arm64/gic-v3-its-cmd.c @@ -0,0 +1,459 @@ +/* + * Copyright (C) 2020, Red Hat Inc, Eric Auger + * + * Most of the code is copy-pasted from: + * drivers/irqchip/irq-gic-v3-its.c + * This work is licensed under the terms of the GNU LGPL, version 2. + */ +#include +#include + +#define ITS_ITT_ALIGN SZ_256 + +static const char * const its_cmd_string[] = { + [GITS_CMD_MAPD] = "MAPD", + [GITS_CMD_MAPC] = "MAPC", + [GITS_CMD_MAPTI] = "MAPTI", + [GITS_CMD_MAPI] = "MAPI", + [GITS_CMD_MOVI] = "MOVI", + [GITS_CMD_DISCARD] = "DISCARD", + [GITS_CMD_INV] = "INV", + [GITS_CMD_MOVALL] = "MOVALL", + [GITS_CMD_INVALL] = "INVALL", + [GITS_CMD_INT] = "INT", + [GITS_CMD_CLEAR] = "CLEAR", + [GITS_CMD_SYNC] = "SYNC", +}; + +struct its_cmd_desc { + union { + struct { + struct its_device *dev; + u32 event_id; + } its_inv_cmd; + + struct { + struct its_device *dev; + u32 event_id; + } its_int_cmd; + + struct { + struct its_device *dev; + bool valid; + } its_mapd_cmd; + + struct { + struct its_collection *col; + bool valid; + } its_mapc_cmd; + + struct { + struct its_device *dev; + u32 phys_id; + u32 event_id; + u32 col_id; + } its_mapti_cmd; + + struct { + struct its_device *dev; + struct its_collection *col; + u32 event_id; + } its_movi_cmd; + + struct { + struct its_device *dev; + u32 event_id; + } its_discard_cmd; + + struct { + struct its_device *dev; + u32 event_id; + } its_clear_cmd; + + struct { + struct its_collection *col; + } its_invall_cmd; + + struct { + struct its_collection *col; + } its_sync_cmd; + }; + bool verbose; +}; + +typedef void (*its_cmd_builder_t)(struct its_cmd_block *, + struct its_cmd_desc *); + +/* ITS COMMANDS */ + +static void its_mask_encode(u64 *raw_cmd, u64 val, int h, int l) +{ + u64 mask = GENMASK_ULL(h, l); + *raw_cmd &= ~mask; + *raw_cmd |= (val << l) & mask; +} + +static void its_encode_cmd(struct its_cmd_block *cmd, u8 cmd_nr) +{ + its_mask_encode(&cmd->raw_cmd[0], cmd_nr, 7, 0); +} + +static void its_encode_devid(struct its_cmd_block *cmd, u32 devid) +{ + its_mask_encode(&cmd->raw_cmd[0], devid, 63, 32); +} + +static void its_encode_event_id(struct its_cmd_block *cmd, u32 id) +{ + its_mask_encode(&cmd->raw_cmd[1], id, 31, 0); +} + +static void its_encode_phys_id(struct its_cmd_block *cmd, u32 phys_id) +{ + its_mask_encode(&cmd->raw_cmd[1], phys_id, 63, 32); +} + +static void its_encode_size(struct its_cmd_block *cmd, u8 size) +{ + its_mask_encode(&cmd->raw_cmd[1], size, 4, 0); +} + +static void its_encode_itt(struct its_cmd_block *cmd, u64 itt_addr) +{ + its_mask_encode(&cmd->raw_cmd[2], itt_addr >> 8, 50, 8); +} + +static void its_encode_valid(struct its_cmd_block *cmd, int valid) +{ + its_mask_encode(&cmd->raw_cmd[2], !!valid, 63, 63); +} + +static void its_encode_target(struct its_cmd_block *cmd, u64 target_addr) +{ + its_mask_encode(&cmd->raw_cmd[2], target_addr >> 16, 50, 16); +} + +static void its_encode_collection(struct its_cmd_block *cmd, u16 col) +{ + its_mask_encode(&cmd->raw_cmd[2], col, 15, 0); +} + +static inline void its_fixup_cmd(struct its_cmd_block *cmd) +{ + /* Let's fixup BE commands */ + cmd->raw_cmd[0] = cpu_to_le64(cmd->raw_cmd[0]); + cmd->raw_cmd[1] = cpu_to_le64(cmd->raw_cmd[1]); + cmd->raw_cmd[2] = cpu_to_le64(cmd->raw_cmd[2]); + cmd->raw_cmd[3] = cpu_to_le64(cmd->raw_cmd[3]); +} + +static u64 its_cmd_ptr_to_offset(struct its_cmd_block *ptr) +{ + return (ptr - its_data.cmd_base) * sizeof(*ptr); +} + +static struct its_cmd_block *its_post_commands(void) +{ + u64 wr = its_cmd_ptr_to_offset(its_data.cmd_write); + + writeq(wr, its_data.base + GITS_CWRITER); + return its_data.cmd_write; +} + +static struct its_cmd_block *its_allocate_entry(void) +{ + struct its_cmd_block *cmd; + + assert((u64)its_data.cmd_write < (u64)its_data.cmd_base + SZ_64K); + cmd = its_data.cmd_write++; + return cmd; +} + +static void its_wait_for_range_completion(struct its_cmd_block *from, + struct its_cmd_block *to) +{ + u64 rd_idx, from_idx, to_idx; + u32 count = 1000000; /* 1s! */ + + from_idx = its_cmd_ptr_to_offset(from); + to_idx = its_cmd_ptr_to_offset(to); + while (1) { + rd_idx = readq(its_data.base + GITS_CREADR); + if (rd_idx >= to_idx || rd_idx < from_idx) + break; + + count--; + if (!count) { + unsigned int cmd_id = from->raw_cmd[0] & 0xFF; + + assert_msg(false, "%s timeout!", + cmd_id <= 0xF ? its_cmd_string[cmd_id] : + "Unexpected"); + } + udelay(1); + } +} + +static void its_send_single_command(its_cmd_builder_t builder, + struct its_cmd_desc *desc) +{ + struct its_cmd_block *cmd, *next_cmd; + + cmd = its_allocate_entry(); + builder(cmd, desc); + next_cmd = its_post_commands(); + + its_wait_for_range_completion(cmd, next_cmd); +} + +static void its_build_mapd_cmd(struct its_cmd_block *cmd, + struct its_cmd_desc *desc) +{ + unsigned long itt_addr; + u8 size = desc->its_mapd_cmd.dev->nr_ites; + + itt_addr = (unsigned long)(virt_to_phys(desc->its_mapd_cmd.dev->itt)); + itt_addr = ALIGN(itt_addr, ITS_ITT_ALIGN); + + its_encode_cmd(cmd, GITS_CMD_MAPD); + its_encode_devid(cmd, desc->its_mapd_cmd.dev->device_id); + its_encode_size(cmd, size - 1); + its_encode_itt(cmd, itt_addr); + its_encode_valid(cmd, desc->its_mapd_cmd.valid); + its_fixup_cmd(cmd); + if (desc->verbose) + printf("ITS: MAPD devid=%d size = 0x%x itt=0x%lx valid=%d\n", + desc->its_mapd_cmd.dev->device_id, + size, itt_addr, desc->its_mapd_cmd.valid); +} + +static void its_build_mapc_cmd(struct its_cmd_block *cmd, + struct its_cmd_desc *desc) +{ + its_encode_cmd(cmd, GITS_CMD_MAPC); + its_encode_collection(cmd, desc->its_mapc_cmd.col->col_id); + its_encode_target(cmd, desc->its_mapc_cmd.col->target_address); + its_encode_valid(cmd, desc->its_mapc_cmd.valid); + its_fixup_cmd(cmd); + if (desc->verbose) + printf("MAPC col_id=%d target_addr = 0x%lx valid=%d\n", + desc->its_mapc_cmd.col->col_id, + desc->its_mapc_cmd.col->target_address, + desc->its_mapc_cmd.valid); +} + +static void its_build_mapti_cmd(struct its_cmd_block *cmd, + struct its_cmd_desc *desc) +{ + its_encode_cmd(cmd, GITS_CMD_MAPTI); + its_encode_devid(cmd, desc->its_mapti_cmd.dev->device_id); + its_encode_event_id(cmd, desc->its_mapti_cmd.event_id); + its_encode_phys_id(cmd, desc->its_mapti_cmd.phys_id); + its_encode_collection(cmd, desc->its_mapti_cmd.col_id); + its_fixup_cmd(cmd); + if (desc->verbose) + printf("MAPTI dev_id=%d event_id=%d -> phys_id=%d, col_id=%d\n", + desc->its_mapti_cmd.dev->device_id, + desc->its_mapti_cmd.event_id, + desc->its_mapti_cmd.phys_id, + desc->its_mapti_cmd.col_id); +} + +static void its_build_invall_cmd(struct its_cmd_block *cmd, + struct its_cmd_desc *desc) +{ + its_encode_cmd(cmd, GITS_CMD_INVALL); + its_encode_collection(cmd, desc->its_invall_cmd.col->col_id); + its_fixup_cmd(cmd); + if (desc->verbose) + printf("INVALL col_id=%d\n", desc->its_invall_cmd.col->col_id); +} + +static void its_build_clear_cmd(struct its_cmd_block *cmd, + struct its_cmd_desc *desc) +{ + its_encode_cmd(cmd, GITS_CMD_CLEAR); + its_encode_devid(cmd, desc->its_clear_cmd.dev->device_id); + its_encode_event_id(cmd, desc->its_clear_cmd.event_id); + its_fixup_cmd(cmd); + if (desc->verbose) + printf("CLEAR dev_id=%d event_id=%d\n", desc->its_clear_cmd.dev->device_id, desc->its_clear_cmd.event_id); +} + +static void its_build_discard_cmd(struct its_cmd_block *cmd, + struct its_cmd_desc *desc) +{ + its_encode_cmd(cmd, GITS_CMD_DISCARD); + its_encode_devid(cmd, desc->its_discard_cmd.dev->device_id); + its_encode_event_id(cmd, desc->its_discard_cmd.event_id); + its_fixup_cmd(cmd); + if (desc->verbose) + printf("DISCARD dev_id=%d event_id=%d\n", + desc->its_clear_cmd.dev->device_id, desc->its_clear_cmd.event_id); +} + +static void its_build_inv_cmd(struct its_cmd_block *cmd, + struct its_cmd_desc *desc) +{ + its_encode_cmd(cmd, GITS_CMD_INV); + its_encode_devid(cmd, desc->its_inv_cmd.dev->device_id); + its_encode_event_id(cmd, desc->its_inv_cmd.event_id); + its_fixup_cmd(cmd); + if (desc->verbose) + printf("INV dev_id=%d event_id=%d\n", + desc->its_inv_cmd.dev->device_id, + desc->its_inv_cmd.event_id); +} + +static void its_build_int_cmd(struct its_cmd_block *cmd, + struct its_cmd_desc *desc) +{ + its_encode_cmd(cmd, GITS_CMD_INT); + its_encode_devid(cmd, desc->its_int_cmd.dev->device_id); + its_encode_event_id(cmd, desc->its_int_cmd.event_id); + its_fixup_cmd(cmd); + if (desc->verbose) + printf("INT dev_id=%d event_id=%d\n", + desc->its_int_cmd.dev->device_id, + desc->its_int_cmd.event_id); +} + +static void its_build_sync_cmd(struct its_cmd_block *cmd, + struct its_cmd_desc *desc) +{ + its_encode_cmd(cmd, GITS_CMD_SYNC); + its_encode_target(cmd, desc->its_sync_cmd.col->target_address); + its_fixup_cmd(cmd); + if (desc->verbose) + printf("SYNC target_addr = 0x%lx\n", + desc->its_sync_cmd.col->target_address); +} + +static void its_build_movi_cmd(struct its_cmd_block *cmd, + struct its_cmd_desc *desc) +{ + its_encode_cmd(cmd, GITS_CMD_MOVI); + its_encode_devid(cmd, desc->its_movi_cmd.dev->device_id); + its_encode_event_id(cmd, desc->its_movi_cmd.event_id); + its_encode_collection(cmd, desc->its_movi_cmd.col->col_id); + its_fixup_cmd(cmd); + if (desc->verbose) + printf("MOVI dev_id=%d event_id = %d col_id=%d\n", + desc->its_movi_cmd.dev->device_id, + desc->its_movi_cmd.event_id, + desc->its_movi_cmd.col->col_id); +} + +void __its_send_mapd(struct its_device *dev, int valid, bool verbose) +{ + struct its_cmd_desc desc; + + desc.its_mapd_cmd.dev = dev; + desc.its_mapd_cmd.valid = !!valid; + desc.verbose = verbose; + + its_send_single_command(its_build_mapd_cmd, &desc); +} + +void __its_send_mapc(struct its_collection *col, int valid, bool verbose) +{ + struct its_cmd_desc desc; + + desc.its_mapc_cmd.col = col; + desc.its_mapc_cmd.valid = !!valid; + desc.verbose = verbose; + + its_send_single_command(its_build_mapc_cmd, &desc); +} + +void __its_send_mapti(struct its_device *dev, u32 irq_id, + u32 event_id, struct its_collection *col, bool verbose) +{ + struct its_cmd_desc desc; + + desc.its_mapti_cmd.dev = dev; + desc.its_mapti_cmd.phys_id = irq_id; + desc.its_mapti_cmd.event_id = event_id; + desc.its_mapti_cmd.col_id = col->col_id; + desc.verbose = verbose; + + its_send_single_command(its_build_mapti_cmd, &desc); +} + +void __its_send_int(struct its_device *dev, u32 event_id, bool verbose) +{ + struct its_cmd_desc desc; + + desc.its_int_cmd.dev = dev; + desc.its_int_cmd.event_id = event_id; + desc.verbose = verbose; + + its_send_single_command(its_build_int_cmd, &desc); +} + +void __its_send_movi(struct its_device *dev, struct its_collection *col, + u32 id, bool verbose) +{ + struct its_cmd_desc desc; + + desc.its_movi_cmd.dev = dev; + desc.its_movi_cmd.col = col; + desc.its_movi_cmd.event_id = id; + desc.verbose = verbose; + + its_send_single_command(its_build_movi_cmd, &desc); +} + +void __its_send_invall(struct its_collection *col, bool verbose) +{ + struct its_cmd_desc desc; + + desc.its_invall_cmd.col = col; + desc.verbose = verbose; + + its_send_single_command(its_build_invall_cmd, &desc); +} + +void __its_send_inv(struct its_device *dev, u32 event_id, bool verbose) +{ + struct its_cmd_desc desc; + + desc.its_inv_cmd.dev = dev; + desc.its_inv_cmd.event_id = event_id; + desc.verbose = verbose; + + its_send_single_command(its_build_inv_cmd, &desc); +} + +void __its_send_discard(struct its_device *dev, u32 event_id, bool verbose) +{ + struct its_cmd_desc desc; + + desc.its_discard_cmd.dev = dev; + desc.its_discard_cmd.event_id = event_id; + desc.verbose = verbose; + + its_send_single_command(its_build_discard_cmd, &desc); +} + +void __its_send_clear(struct its_device *dev, u32 event_id, bool verbose) +{ + struct its_cmd_desc desc; + + desc.its_clear_cmd.dev = dev; + desc.its_clear_cmd.event_id = event_id; + desc.verbose = verbose; + + its_send_single_command(its_build_clear_cmd, &desc); +} + +void __its_send_sync(struct its_collection *col, bool verbose) +{ + struct its_cmd_desc desc; + + desc.its_sync_cmd.col = col; + desc.verbose = verbose; + + its_send_single_command(its_build_sync_cmd, &desc); +} + From patchwork Sat Apr 4 14:37:28 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Andrew Jones X-Patchwork-Id: 11474371 Return-Path: Received: from mail.kernel.org (pdx-korg-mail-1.web.codeaurora.org [172.30.200.123]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 99F6D1392 for ; Sat, 4 Apr 2020 14:39:33 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id 6FC912071C for ; Sat, 4 Apr 2020 14:39:33 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (1024-bit key) header.d=redhat.com header.i=@redhat.com header.b="L0+QUMI3" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726701AbgDDOjc (ORCPT ); Sat, 4 Apr 2020 10:39:32 -0400 Received: from us-smtp-1.mimecast.com ([205.139.110.61]:57563 "EHLO us-smtp-delivery-1.mimecast.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S1726696AbgDDOjc (ORCPT ); Sat, 4 Apr 2020 10:39:32 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1586011170; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=k16DDTfET10bTMMk5weG30wRX2QfIuhsQJXS1PMhmJc=; b=L0+QUMI3x9j0VQPM4nxijAYXChcHxm88sG+N3nZ5mKEU12ujag2E7rvLdQDIolSorsXX/H zYFLNrBXpDicV8ewBoCsULEUXgcQ9JoOcY2Sj6uQMGJFppwmQAqmBinX2BEh9pZ7sgaV95 OGJtAgIPFIa7PKmU/0gkmTE4cdIFv/E= Received: from mimecast-mx01.redhat.com (mimecast-mx01.redhat.com [209.132.183.4]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-496-VexSv7oCPt-RjoBU67Sk2Q-1; Sat, 04 Apr 2020 10:39:27 -0400 X-MC-Unique: VexSv7oCPt-RjoBU67Sk2Q-1 Received: from smtp.corp.redhat.com (int-mx01.intmail.prod.int.phx2.redhat.com [10.5.11.11]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id 2DAA718AB2C4; Sat, 4 Apr 2020 14:39:26 +0000 (UTC) Received: from kamzik.brq.redhat.com (unknown [10.40.192.30]) by smtp.corp.redhat.com (Postfix) with ESMTP id A93FE9B912; Sat, 4 Apr 2020 14:39:24 +0000 (UTC) From: Andrew Jones To: pbonzini@redhat.com Cc: kvm@vger.kernel.org, kvmarm@lists.cs.columbia.edu, Eric Auger , Zenghui Yu Subject: [PULL kvm-unit-tests 36/39] arm/arm64: ITS: INT functional tests Date: Sat, 4 Apr 2020 16:37:28 +0200 Message-Id: <20200404143731.208138-37-drjones@redhat.com> In-Reply-To: <20200404143731.208138-1-drjones@redhat.com> References: <20200404143731.208138-1-drjones@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.11 Sender: kvm-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: kvm@vger.kernel.org From: Eric Auger Triggers LPIs through the INT command. the test checks the LPI hits the right CPU and triggers the right LPI intid, ie. the translation is correct. Updates to the config table also are tested, along with inv and invall commands. Signed-off-by: Eric Auger Reviewed-by: Zenghui Yu Signed-off-by: Andrew Jones --- arm/gic.c | 217 +++++++++++++++++++++++++++++++++++++++++++--- arm/unittests.cfg | 7 ++ 2 files changed, 213 insertions(+), 11 deletions(-) diff --git a/arm/gic.c b/arm/gic.c index 649ed81d33e1..54ae83d26eb9 100644 --- a/arm/gic.c +++ b/arm/gic.c @@ -159,6 +159,87 @@ static void ipi_handler(struct pt_regs *regs __unused) } } +static void setup_irq(irq_handler_fn handler) +{ + gic_enable_defaults(); +#ifdef __arm__ + install_exception_handler(EXCPTN_IRQ, handler); +#else + install_irq_handler(EL1H_IRQ, handler); +#endif + local_irq_enable(); +} + +#if defined(__aarch64__) +struct its_event { + int cpu_id; + int lpi_id; +}; + +struct its_stats { + struct its_event expected; + struct its_event observed; +}; + +static struct its_stats lpi_stats; + +static void lpi_handler(struct pt_regs *regs __unused) +{ + u32 irqstat = gic_read_iar(); + int irqnr = gic_iar_irqnr(irqstat); + + gic_write_eoir(irqstat); + assert(irqnr >= 8192); + smp_rmb(); /* pairs with wmb in lpi_stats_expect */ + lpi_stats.observed.cpu_id = smp_processor_id(); + lpi_stats.observed.lpi_id = irqnr; + smp_wmb(); /* pairs with rmb in check_lpi_stats */ +} + +static void lpi_stats_expect(int exp_cpu_id, int exp_lpi_id) +{ + lpi_stats.expected.cpu_id = exp_cpu_id; + lpi_stats.expected.lpi_id = exp_lpi_id; + lpi_stats.observed.cpu_id = -1; + lpi_stats.observed.lpi_id = -1; + smp_wmb(); /* pairs with rmb in handler */ +} + +static void check_lpi_stats(const char *msg) +{ + int i; + + for (i = 0; i < 50; i++) { + mdelay(100); + smp_rmb(); /* pairs with wmb in lpi_handler */ + if (lpi_stats.observed.cpu_id == lpi_stats.expected.cpu_id && + lpi_stats.observed.lpi_id == lpi_stats.expected.lpi_id) { + report(true, "%s", msg); + return; + } + } + + if (lpi_stats.observed.cpu_id == -1 && lpi_stats.observed.lpi_id == -1) { + report_info("No LPI received whereas (cpuid=%d, intid=%d) " + "was expected", lpi_stats.expected.cpu_id, + lpi_stats.expected.lpi_id); + } else { + report_info("Unexpected LPI (cpuid=%d, intid=%d)", + lpi_stats.observed.cpu_id, + lpi_stats.observed.lpi_id); + } + report(false, "%s", msg); +} + +static void secondary_lpi_test(void) +{ + setup_irq(lpi_handler); + cpumask_set_cpu(smp_processor_id(), &ready); + while (1) + wfi(); +} +#endif + static void gicv2_ipi_send_self(void) { writel(2 << 24 | IPI_IRQ, gicv2_dist_base() + GICD_SGIR); @@ -216,17 +297,6 @@ static void ipi_test_smp(void) report_prefix_pop(); } -static void setup_irq(irq_handler_fn handler) -{ - gic_enable_defaults(); -#ifdef __arm__ - install_exception_handler(EXCPTN_IRQ, handler); -#else - install_irq_handler(EL1H_IRQ, handler); -#endif - local_irq_enable(); -} - static void ipi_send(void) { setup_irq(ipi_handler); @@ -521,6 +591,7 @@ static void gic_test_mmio(void) #if defined(__arm__) static void test_its_introspection(void) {} +static void test_its_trigger(void) {} #else /* __aarch64__ */ @@ -559,6 +630,126 @@ static void test_its_introspection(void) report_info("collection table entry_size = 0x%x", coll_baser->esz); } +static int its_prerequisites(int nb_cpus) +{ + int cpu; + + if (!gicv3_its_base()) { + report_skip("No ITS, skip ..."); + return -1; + } + + if (nr_cpus < nb_cpus) { + report_skip("Test requires at least %d vcpus", nb_cpus); + return -1; + } + + stats_reset(); + + setup_irq(lpi_handler); + + for_each_present_cpu(cpu) { + if (cpu == 0) + continue; + smp_boot_secondary(cpu, secondary_lpi_test); + } + wait_on_ready(); + + its_enable_defaults(); + + return 0; +} + +static void test_its_trigger(void) +{ + struct its_collection *col3, *col2; + struct its_device *dev2, *dev7; + + if (its_prerequisites(4)) + return; + + dev2 = its_create_device(2 /* dev id */, 8 /* nb_ites */); + dev7 = its_create_device(7 /* dev id */, 8 /* nb_ites */); + + col3 = its_create_collection(3 /* col id */, 3/* target PE */); + col2 = its_create_collection(2 /* col id */, 2/* target PE */); + + gicv3_lpi_set_config(8195, LPI_PROP_DEFAULT); + gicv3_lpi_set_config(8196, LPI_PROP_DEFAULT); + + report_prefix_push("int"); + /* + * dev=2, eventid=20 -> lpi= 8195, col=3 + * dev=7, eventid=255 -> lpi= 8196, col=2 + * Trigger dev2, eventid=20 and dev7, eventid=255 + * Check both LPIs hit + */ + + its_send_mapd(dev2, true); + its_send_mapd(dev7, true); + + its_send_mapc(col3, true); + its_send_mapc(col2, true); + + its_send_invall(col2); + its_send_invall(col3); + + its_send_mapti(dev2, 8195 /* lpi id */, 20 /* event id */, col3); + its_send_mapti(dev7, 8196 /* lpi id */, 255 /* event id */, col2); + + lpi_stats_expect(3, 8195); + its_send_int(dev2, 20); + check_lpi_stats("dev=2, eventid=20 -> lpi= 8195, col=3"); + + lpi_stats_expect(2, 8196); + its_send_int(dev7, 255); + check_lpi_stats("dev=7, eventid=255 -> lpi= 8196, col=2"); + + report_prefix_pop(); + + report_prefix_push("inv/invall"); + + /* + * disable 8195, check dev2/eventid=20 does not trigger the + * corresponding LPI + */ + gicv3_lpi_set_config(8195, LPI_PROP_DEFAULT & ~LPI_PROP_ENABLED); + its_send_inv(dev2, 20); + + lpi_stats_expect(-1, -1); + its_send_int(dev2, 20); + check_lpi_stats("dev2/eventid=20 does not trigger any LPI"); + + /* + * re-enable the LPI but willingly do not call invall + * so the change in config is not taken into account. + * The LPI should not hit + */ + gicv3_lpi_set_config(8195, LPI_PROP_DEFAULT); + lpi_stats_expect(-1, -1); + its_send_int(dev2, 20); + check_lpi_stats("dev2/eventid=20 still does not trigger any LPI"); + + /* Now call the invall and check the LPI hits */ + its_send_invall(col3); + lpi_stats_expect(3, 8195); + its_send_int(dev2, 20); + check_lpi_stats("dev2/eventid=20 now triggers an LPI"); + + report_prefix_pop(); + + report_prefix_push("mapd valid=false"); + /* + * Unmap device 2 and check the eventid 20 formerly + * attached to it does not hit anymore + */ + + its_send_mapd(dev2, false); + lpi_stats_expect(-1, -1); + its_send_int(dev2, 20); + check_lpi_stats("no LPI after device unmap"); + report_prefix_pop(); +} #endif int main(int argc, char **argv) @@ -592,6 +783,10 @@ int main(int argc, char **argv) report_prefix_push(argv[1]); gic_test_mmio(); report_prefix_pop(); + } else if (!strcmp(argv[1], "its-trigger")) { + report_prefix_push(argv[1]); + test_its_trigger(); + report_prefix_pop(); } else if (strcmp(argv[1], "its-introspection") == 0) { report_prefix_push(argv[1]); test_its_introspection(); diff --git a/arm/unittests.cfg b/arm/unittests.cfg index fff37f9fb5e6..47f9446adcc3 100644 --- a/arm/unittests.cfg +++ b/arm/unittests.cfg @@ -184,6 +184,13 @@ extra_params = -machine gic-version=3 -append 'its-introspection' groups = its arch = arm64 +[its-trigger] +file = gic.flat +smp = $MAX_SMP +extra_params = -machine gic-version=3 -append 'its-trigger' +groups = its +arch = arm64 + # Test PSCI emulation [psci] file = psci.flat From patchwork Sat Apr 4 14:37:29 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Andrew Jones X-Patchwork-Id: 11474379 Return-Path: Received: from mail.kernel.org (pdx-korg-mail-1.web.codeaurora.org [172.30.200.123]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 0BB75912 for ; Sat, 4 Apr 2020 14:39:38 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id DEEBB20738 for ; Sat, 4 Apr 2020 14:39:37 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (1024-bit key) header.d=redhat.com header.i=@redhat.com header.b="SBhbQtRJ" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726716AbgDDOjh (ORCPT ); Sat, 4 Apr 2020 10:39:37 -0400 Received: from us-smtp-delivery-1.mimecast.com ([205.139.110.120]:38337 "EHLO us-smtp-1.mimecast.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S1726705AbgDDOjg (ORCPT ); Sat, 4 Apr 2020 10:39:36 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1586011175; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=tCVC87LkZJzjp0nWYU+R4308nabVVB1yt9ifphXuw5Y=; b=SBhbQtRJXLmW/caB3xJUGn8vr/UbAw+uI8E0efnUiAlPQbEjrdVtkvtYQzFpuHUcfxU8Lo rCdv3iZL/yX8/eLBi9VRWDQx1m08G1BbinQJedwWMiUBhPE15A3ehfZZ6/B3MMoHVSQZ6j WWsjyOGPaf3ma6uGUiTeGZ1vmGA0AJU= Received: from mimecast-mx01.redhat.com (mimecast-mx01.redhat.com [209.132.183.4]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-494-DRO7e7xkPU6k4HhiPkLdSA-1; Sat, 04 Apr 2020 10:39:28 -0400 X-MC-Unique: DRO7e7xkPU6k4HhiPkLdSA-1 Received: from smtp.corp.redhat.com (int-mx01.intmail.prod.int.phx2.redhat.com [10.5.11.11]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id CD3BEDB22; Sat, 4 Apr 2020 14:39:27 +0000 (UTC) Received: from kamzik.brq.redhat.com (unknown [10.40.192.30]) by smtp.corp.redhat.com (Postfix) with ESMTP id 824B89B912; Sat, 4 Apr 2020 14:39:26 +0000 (UTC) From: Andrew Jones To: pbonzini@redhat.com Cc: kvm@vger.kernel.org, kvmarm@lists.cs.columbia.edu, Eric Auger Subject: [PULL kvm-unit-tests 37/39] arm/run: Allow Migration tests Date: Sat, 4 Apr 2020 16:37:29 +0200 Message-Id: <20200404143731.208138-38-drjones@redhat.com> In-Reply-To: <20200404143731.208138-1-drjones@redhat.com> References: <20200404143731.208138-1-drjones@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.11 Sender: kvm-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: kvm@vger.kernel.org From: Eric Auger Let's link getchar.o to use puts and getchar from the tests. Then allow tests belonging to the migration group to trigger the migration from the test code by putting "migrate" into the uart. Then the code can wait for the migration completion by using getchar(). The __getchar implement is minimalist as it just reads the data register. It is just meant to read the single character emitted at the end of the migration by the runner script. It is not meant to read more data (FIFOs are not enabled). Signed-off-by: Eric Auger Signed-off-by: Andrew Jones --- arm/Makefile.common | 2 +- arm/run | 2 +- lib/arm/io.c | 28 ++++++++++++++++++++++++++++ 3 files changed, 30 insertions(+), 2 deletions(-) diff --git a/arm/Makefile.common b/arm/Makefile.common index b8988f214d3b..a123e85d21bc 100644 --- a/arm/Makefile.common +++ b/arm/Makefile.common @@ -32,7 +32,7 @@ CFLAGS += -I $(SRCDIR)/lib -I $(SRCDIR)/lib/libfdt -I lib asm-offsets = lib/$(ARCH)/asm-offsets.h include $(SRCDIR)/scripts/asm-offsets.mak -cflatobjs += lib/util.o +cflatobjs += lib/util.o lib/getchar.o cflatobjs += lib/alloc_phys.o cflatobjs += lib/alloc_page.o cflatobjs += lib/vmalloc.o diff --git a/arm/run b/arm/run index 277db9bb4a02..a390ca5ae0ba 100755 --- a/arm/run +++ b/arm/run @@ -61,6 +61,6 @@ fi M+=",accel=$ACCEL" command="$qemu -nodefaults $M -cpu $processor $chr_testdev $pci_testdev" command+=" -display none -serial stdio -kernel" -command="$(timeout_cmd) $command" +command="$(migration_cmd) $(timeout_cmd) $command" run_qemu $command "$@" diff --git a/lib/arm/io.c b/lib/arm/io.c index 99fd31560084..343e10822263 100644 --- a/lib/arm/io.c +++ b/lib/arm/io.c @@ -87,6 +87,34 @@ void puts(const char *s) spin_unlock(&uart_lock); } +static int do_getchar(void) +{ + int c; + + spin_lock(&uart_lock); + c = readb(uart0_base); + spin_unlock(&uart_lock); + + return c ?: -1; +} + +/* + * Minimalist implementation for migration completion detection. + * Without FIFOs enabled on the QEMU UART device we just read + * the data register: we cannot read more than 16 characters. + */ +int __getchar(void) +{ + int c = do_getchar(); + static int count; + + if (c != -1) + ++count; + + assert(count < 16); + + return c; +} /* * Defining halt to take 'code' as an argument guarantees that it will From patchwork Sat Apr 4 14:37:30 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Andrew Jones X-Patchwork-Id: 11474375 Return-Path: Received: from mail.kernel.org (pdx-korg-mail-1.web.codeaurora.org [172.30.200.123]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 24B8A1392 for ; Sat, 4 Apr 2020 14:39:37 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id 0310D206F5 for ; Sat, 4 Apr 2020 14:39:37 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (1024-bit key) header.d=redhat.com header.i=@redhat.com header.b="OaPvbMu+" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726230AbgDDOjg (ORCPT ); Sat, 4 Apr 2020 10:39:36 -0400 Received: from us-smtp-delivery-1.mimecast.com ([205.139.110.120]:50428 "EHLO us-smtp-1.mimecast.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S1726593AbgDDOjf (ORCPT ); Sat, 4 Apr 2020 10:39:35 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1586011175; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=QNG141TmX85y30XV5pUtpTniRxPlixz+Zq4HHGjDFaQ=; b=OaPvbMu+eLlik3w43kMIiavcHPKiYmG/EQvoX3Zk3WMLng9f7YtTep7rol4YRb2oU6fFw/ 9bNZkWE5p7ok6HoWc7jhxmDlmOdYVy4CI0XAYjfnUmxV56Jh1eZLTPKk+iYym7Z23vv69k QPkd84DmWKmqG7FTjmJ1eMnn/T4q9a0= Received: from mimecast-mx01.redhat.com (mimecast-mx01.redhat.com [209.132.183.4]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-40-THYbQIZAO1O17HkrSuL1ZA-1; Sat, 04 Apr 2020 10:39:30 -0400 X-MC-Unique: THYbQIZAO1O17HkrSuL1ZA-1 Received: from smtp.corp.redhat.com (int-mx01.intmail.prod.int.phx2.redhat.com [10.5.11.11]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id A70B41005516; Sat, 4 Apr 2020 14:39:29 +0000 (UTC) Received: from kamzik.brq.redhat.com (unknown [10.40.192.30]) by smtp.corp.redhat.com (Postfix) with ESMTP id 2EEB39B912; Sat, 4 Apr 2020 14:39:28 +0000 (UTC) From: Andrew Jones To: pbonzini@redhat.com Cc: kvm@vger.kernel.org, kvmarm@lists.cs.columbia.edu, Eric Auger , Zenghui Yu Subject: [PULL kvm-unit-tests 38/39] arm/arm64: ITS: migration tests Date: Sat, 4 Apr 2020 16:37:30 +0200 Message-Id: <20200404143731.208138-39-drjones@redhat.com> In-Reply-To: <20200404143731.208138-1-drjones@redhat.com> References: <20200404143731.208138-1-drjones@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.11 Sender: kvm-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: kvm@vger.kernel.org From: Eric Auger This test maps LPIs (populates the device table, the collection table, interrupt translation tables, configuration table), migrates and make sure the translation is correct on the destination. Signed-off-by: Eric Auger Reviewed-by: Zenghui Yu [ Complete migration even when the test is skipped. Otherwise the migration scripts hang. ] Signed-off-by: Andrew Jones --- arm/gic.c | 64 ++++++++++++++++++++++++++++++++++---- arm/unittests.cfg | 8 +++++ lib/arm64/asm/gic-v3-its.h | 3 ++ lib/arm64/gic-v3-its.c | 22 +++++++++++++ 4 files changed, 91 insertions(+), 6 deletions(-) diff --git a/arm/gic.c b/arm/gic.c index 54ae83d26eb9..d98d70a5d9e9 100644 --- a/arm/gic.c +++ b/arm/gic.c @@ -592,6 +592,7 @@ static void gic_test_mmio(void) static void test_its_introspection(void) {} static void test_its_trigger(void) {} +static void test_its_migration(void) {} #else /* __aarch64__ */ @@ -660,13 +661,19 @@ static int its_prerequisites(int nb_cpus) return 0; } -static void test_its_trigger(void) +/* + * Setup the configuration for those mappings: + * dev_id=2 event=20 -> vcpu 3, intid=8195 + * dev_id=7 event=255 -> vcpu 2, intid=8196 + * LPIs ready to hit + */ +static int its_setup1(void) { struct its_collection *col3, *col2; struct its_device *dev2, *dev7; if (its_prerequisites(4)) - return; + return -1; dev2 = its_create_device(2 /* dev id */, 8 /* nb_ites */); dev7 = its_create_device(7 /* dev id */, 8 /* nb_ites */); @@ -677,14 +684,10 @@ static void test_its_trigger(void) gicv3_lpi_set_config(8195, LPI_PROP_DEFAULT); gicv3_lpi_set_config(8196, LPI_PROP_DEFAULT); - report_prefix_push("int"); /* * dev=2, eventid=20 -> lpi= 8195, col=3 * dev=7, eventid=255 -> lpi= 8196, col=2 - * Trigger dev2, eventid=20 and dev7, eventid=255 - * Check both LPIs hit */ - its_send_mapd(dev2, true); its_send_mapd(dev7, true); @@ -696,6 +699,22 @@ static void test_its_trigger(void) its_send_mapti(dev2, 8195 /* lpi id */, 20 /* event id */, col3); its_send_mapti(dev7, 8196 /* lpi id */, 255 /* event id */, col2); + return 0; +} + +static void test_its_trigger(void) +{ + struct its_collection *col3; + struct its_device *dev2, *dev7; + + if (its_setup1()) + return; + + col3 = its_get_collection(3); + dev2 = its_get_device(2); + dev7 = its_get_device(7); + + report_prefix_push("int"); lpi_stats_expect(3, 8195); its_send_int(dev2, 20); @@ -750,6 +769,35 @@ static void test_its_trigger(void) check_lpi_stats("no LPI after device unmap"); report_prefix_pop(); } + +static void test_its_migration(void) +{ + struct its_device *dev2, *dev7; + bool test_skipped = false; + + if (its_setup1()) { + test_skipped = true; + goto do_migrate; + } + + dev2 = its_get_device(2); + dev7 = its_get_device(7); + +do_migrate: + puts("Now migrate the VM, then press a key to continue...\n"); + (void)getchar(); + report_info("Migration complete"); + if (test_skipped) + return; + + lpi_stats_expect(3, 8195); + its_send_int(dev2, 20); + check_lpi_stats("dev2/eventid=20 triggers LPI 8195 on PE #3 after migration"); + + lpi_stats_expect(2, 8196); + its_send_int(dev7, 255); + check_lpi_stats("dev7/eventid=255 triggers LPI 8196 on PE #2 after migration"); +} #endif int main(int argc, char **argv) @@ -787,6 +835,10 @@ int main(int argc, char **argv) report_prefix_push(argv[1]); test_its_trigger(); report_prefix_pop(); + } else if (!strcmp(argv[1], "its-migration")) { + report_prefix_push(argv[1]); + test_its_migration(); + report_prefix_pop(); } else if (strcmp(argv[1], "its-introspection") == 0) { report_prefix_push(argv[1]); test_its_introspection(); diff --git a/arm/unittests.cfg b/arm/unittests.cfg index 47f9446adcc3..20a1ae269571 100644 --- a/arm/unittests.cfg +++ b/arm/unittests.cfg @@ -191,6 +191,14 @@ extra_params = -machine gic-version=3 -append 'its-trigger' groups = its arch = arm64 +[its-migration] +file = gic.flat +smp = $MAX_SMP +accel = kvm +extra_params = -machine gic-version=3 -append 'its-migration' +groups = its migration +arch = arm64 + # Test PSCI emulation [psci] file = psci.flat diff --git a/lib/arm64/asm/gic-v3-its.h b/lib/arm64/asm/gic-v3-its.h index c203293a7838..0258daa15709 100644 --- a/lib/arm64/asm/gic-v3-its.h +++ b/lib/arm64/asm/gic-v3-its.h @@ -168,4 +168,7 @@ extern void __its_send_sync(struct its_collection *col, bool verbose); #define its_send_movi_nv(dev, col, id) __its_send_movi(dev, col, id, false) #define its_send_sync_nv(col) __its_send_sync(col, false) +extern struct its_device *its_get_device(u32 id); +extern struct its_collection *its_get_collection(u32 id); + #endif /* _ASMARM64_GIC_V3_ITS_H_ */ diff --git a/lib/arm64/gic-v3-its.c b/lib/arm64/gic-v3-its.c index ca91c3dd1108..c22bda3a8ba2 100644 --- a/lib/arm64/gic-v3-its.c +++ b/lib/arm64/gic-v3-its.c @@ -147,3 +147,25 @@ struct its_collection *its_create_collection(u16 col_id, u32 pe) its_data.nr_collections++; return new; } + +struct its_device *its_get_device(u32 id) +{ + int i; + + for (i = 0; i < GITS_MAX_DEVICES; i++) { + if (its_data.devices[i].device_id == id) + return &its_data.devices[i]; + } + assert(0); +} + +struct its_collection *its_get_collection(u32 id) +{ + int i; + + for (i = 0; i < GITS_MAX_COLLECTIONS; i++) { + if (its_data.collections[i].col_id == id) + return &its_data.collections[i]; + } + assert(0); +} From patchwork Sat Apr 4 14:37:31 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Andrew Jones X-Patchwork-Id: 11474377 Return-Path: Received: from mail.kernel.org (pdx-korg-mail-1.web.codeaurora.org [172.30.200.123]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 8B72115AB for ; Sat, 4 Apr 2020 14:39:37 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id 610F920738 for ; Sat, 4 Apr 2020 14:39:37 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (1024-bit key) header.d=redhat.com header.i=@redhat.com header.b="IWPv0Z/l" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726706AbgDDOjg (ORCPT ); Sat, 4 Apr 2020 10:39:36 -0400 Received: from us-smtp-delivery-1.mimecast.com ([205.139.110.120]:42926 "EHLO us-smtp-1.mimecast.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S1726683AbgDDOjf (ORCPT ); Sat, 4 Apr 2020 10:39:35 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1586011174; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=uvnZtk9MYZ3Ee6O6BcV8wY1ClITdYU83OUWZcVLM8OQ=; b=IWPv0Z/lQOiLdnQf3sKe+pvSrQia7JeP77NR+odZUSC/TPl5aBdwaKadVFGn0ER2B9MQAp q68b/lDcd+n5aQM/bjIx4lBsrpnJkH+KiI+J0Xxjwl3TgjB1oB6ZNqui/cTF3o1Gs4EWJ8 jhbBr5V8TozoesWrwWHLKprpjsGOrcQ= Received: from mimecast-mx01.redhat.com (mimecast-mx01.redhat.com [209.132.183.4]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-110-q4bsuQKJOnOrl5rpaXtw8A-1; Sat, 04 Apr 2020 10:39:32 -0400 X-MC-Unique: q4bsuQKJOnOrl5rpaXtw8A-1 Received: from smtp.corp.redhat.com (int-mx01.intmail.prod.int.phx2.redhat.com [10.5.11.11]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id 57D6E8017CE; Sat, 4 Apr 2020 14:39:31 +0000 (UTC) Received: from kamzik.brq.redhat.com (unknown [10.40.192.30]) by smtp.corp.redhat.com (Postfix) with ESMTP id 0810A9B912; Sat, 4 Apr 2020 14:39:29 +0000 (UTC) From: Andrew Jones To: pbonzini@redhat.com Cc: kvm@vger.kernel.org, kvmarm@lists.cs.columbia.edu, Eric Auger Subject: [PULL kvm-unit-tests 39/39] arm/arm64: ITS: pending table migration test Date: Sat, 4 Apr 2020 16:37:31 +0200 Message-Id: <20200404143731.208138-40-drjones@redhat.com> In-Reply-To: <20200404143731.208138-1-drjones@redhat.com> References: <20200404143731.208138-1-drjones@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.11 Sender: kvm-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: kvm@vger.kernel.org From: Eric Auger Add two new migration tests. One testing the migration of a topology where collection were unmapped. The second test checks the migration of the pending table. Signed-off-by: Eric Auger [ Complete migration even when the test is skipped. Otherwise the migration scripts hang. Also, without the KVM fix for unmapped collections, migration will fail and the test will hang, so use errata to skip it instead. ] Signed-off-by: Andrew Jones --- arm/gic.c | 152 ++++++++++++++++++++++++++++++++++++++++++++++ arm/unittests.cfg | 16 +++++ errata.txt | 1 + 3 files changed, 169 insertions(+) diff --git a/arm/gic.c b/arm/gic.c index d98d70a5d9e9..dc1e88c67a9c 100644 --- a/arm/gic.c +++ b/arm/gic.c @@ -12,6 +12,7 @@ * This work is licensed under the terms of the GNU LGPL, version 2. */ #include +#include #include #include #include @@ -193,6 +194,7 @@ static void lpi_handler(struct pt_regs *regs __unused) smp_rmb(); /* pairs with wmb in lpi_stats_expect */ lpi_stats.observed.cpu_id = smp_processor_id(); lpi_stats.observed.lpi_id = irqnr; + acked[lpi_stats.observed.cpu_id]++; smp_wmb(); /* pairs with rmb in check_lpi_stats */ } @@ -238,6 +240,22 @@ static void secondary_lpi_test(void) while (1) wfi(); } + +static void check_lpi_hits(int *expected, const char *msg) +{ + bool pass = true; + int i; + + for_each_present_cpu(i) { + if (acked[i] != expected[i]) { + report_info("expected %d LPIs on PE #%d, %d observed", + expected[i], i, acked[i]); + pass = false; + break; + } + } + report(pass, "%s", msg); +} #endif static void gicv2_ipi_send_self(void) @@ -593,6 +611,8 @@ static void gic_test_mmio(void) static void test_its_introspection(void) {} static void test_its_trigger(void) {} static void test_its_migration(void) {} +static void test_its_pending_migration(void) {} +static void test_migrate_unmapped_collection(void) {} #else /* __aarch64__ */ @@ -798,6 +818,130 @@ do_migrate: its_send_int(dev7, 255); check_lpi_stats("dev7/eventid=255 triggers LPI 8196 on PE #2 after migration"); } + +#define ERRATA_UNMAPPED_COLLECTIONS "ERRATA_8c58be34494b" + +static void test_migrate_unmapped_collection(void) +{ + struct its_collection *col = NULL; + struct its_device *dev2 = NULL, *dev7 = NULL; + bool test_skipped = false; + int pe0 = 0; + u8 config; + + if (its_setup1()) { + test_skipped = true; + goto do_migrate; + } + + if (!errata(ERRATA_UNMAPPED_COLLECTIONS)) { + report_skip("Skipping test, as this test hangs without the fix. " + "Set %s=y to enable.", ERRATA_UNMAPPED_COLLECTIONS); + test_skipped = true; + goto do_migrate; + } + + col = its_create_collection(pe0, pe0); + dev2 = its_get_device(2); + dev7 = its_get_device(7); + + /* MAPTI with the collection unmapped */ + its_send_mapti(dev2, 8192, 0, col); + gicv3_lpi_set_config(8192, LPI_PROP_DEFAULT); + +do_migrate: + puts("Now migrate the VM, then press a key to continue...\n"); + (void)getchar(); + report_info("Migration complete"); + if (test_skipped) + return; + + /* on the destination, map the collection */ + its_send_mapc(col, true); + its_send_invall(col); + + lpi_stats_expect(2, 8196); + its_send_int(dev7, 255); + check_lpi_stats("dev7/eventid= 255 triggered LPI 8196 on PE #2"); + + config = gicv3_lpi_get_config(8192); + report(config == LPI_PROP_DEFAULT, + "Config of LPI 8192 was properly migrated"); + + lpi_stats_expect(pe0, 8192); + its_send_int(dev2, 0); + check_lpi_stats("dev2/eventid = 0 triggered LPI 8192 on PE0"); +} + +static void test_its_pending_migration(void) +{ + struct its_device *dev; + struct its_collection *collection[2]; + int *expected = calloc(nr_cpus, sizeof(int)); + int pe0 = nr_cpus - 1, pe1 = nr_cpus - 2; + bool test_skipped = false; + u64 pendbaser; + void *ptr; + int i; + + if (its_prerequisites(4)) { + test_skipped = true; + goto do_migrate; + } + + dev = its_create_device(2 /* dev id */, 8 /* nb_ites */); + its_send_mapd(dev, true); + + collection[0] = its_create_collection(pe0, pe0); + collection[1] = its_create_collection(pe1, pe1); + its_send_mapc(collection[0], true); + its_send_mapc(collection[1], true); + + /* disable lpi at redist level */ + gicv3_lpi_rdist_disable(pe0); + gicv3_lpi_rdist_disable(pe1); + + /* lpis are interleaved inbetween the 2 PEs */ + for (i = 0; i < 256; i++) { + struct its_collection *col = i % 2 ? collection[0] : + collection[1]; + int vcpu = col->target_address >> 16; + + its_send_mapti(dev, LPI(i), i, col); + gicv3_lpi_set_config(LPI(i), LPI_PROP_DEFAULT); + gicv3_lpi_set_clr_pending(vcpu, LPI(i), true); + } + its_send_invall(collection[0]); + its_send_invall(collection[1]); + + /* Clear the PTZ bit on each pendbaser */ + + expected[pe0] = 128; + expected[pe1] = 128; + + ptr = gicv3_data.redist_base[pe0] + GICR_PENDBASER; + pendbaser = readq(ptr); + writeq(pendbaser & ~GICR_PENDBASER_PTZ, ptr); + + ptr = gicv3_data.redist_base[pe1] + GICR_PENDBASER; + pendbaser = readq(ptr); + writeq(pendbaser & ~GICR_PENDBASER_PTZ, ptr); + + gicv3_lpi_rdist_enable(pe0); + gicv3_lpi_rdist_enable(pe1); + +do_migrate: + puts("Now migrate the VM, then press a key to continue...\n"); + (void)getchar(); + report_info("Migration complete"); + if (test_skipped) + return; + + /* let's wait for the 256 LPIs to be handled */ + mdelay(1000); + + check_lpi_hits(expected, "128 LPIs on both PE0 and PE1 after migration"); +} #endif int main(int argc, char **argv) @@ -839,6 +983,14 @@ int main(int argc, char **argv) report_prefix_push(argv[1]); test_its_migration(); report_prefix_pop(); + } else if (!strcmp(argv[1], "its-pending-migration")) { + report_prefix_push(argv[1]); + test_its_pending_migration(); + report_prefix_pop(); + } else if (!strcmp(argv[1], "its-migrate-unmapped-collection")) { + report_prefix_push(argv[1]); + test_migrate_unmapped_collection(); + report_prefix_pop(); } else if (strcmp(argv[1], "its-introspection") == 0) { report_prefix_push(argv[1]); test_its_introspection(); diff --git a/arm/unittests.cfg b/arm/unittests.cfg index 20a1ae269571..f776b66ef96d 100644 --- a/arm/unittests.cfg +++ b/arm/unittests.cfg @@ -199,6 +199,22 @@ extra_params = -machine gic-version=3 -append 'its-migration' groups = its migration arch = arm64 +[its-pending-migration] +file = gic.flat +smp = $MAX_SMP +accel = kvm +extra_params = -machine gic-version=3 -append 'its-pending-migration' +groups = its migration +arch = arm64 + +[its-migrate-unmapped-collection] +file = gic.flat +smp = $MAX_SMP +accel = kvm +extra_params = -machine gic-version=3 -append 'its-migrate-unmapped-collection' +groups = its migration +arch = arm64 + # Test PSCI emulation [psci] file = psci.flat diff --git a/errata.txt b/errata.txt index 7d6abc2a7bf6..b66afaa9c079 100644 --- a/errata.txt +++ b/errata.txt @@ -5,4 +5,5 @@ 9e3f7a296940 : 4.9 : arm64: KVM: pmu: Fix AArch32 cycle counter access 7b6b46311a85 : 4.11 : KVM: arm/arm64: Emulate the EL1 phys timer registers 6c7a5dce22b3 : 4.12 : KVM: arm/arm64: fix races in kvm_psci_vcpu_on +8c58be34494b : 5.6 : KVM: arm/arm64: vgic-its: Fix restoration of unmapped collections #---------------:-------------------------------:---------------------------------------------------