From patchwork Mon Jun 25 16:00:09 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: =?utf-8?q?Alex_Benn=C3=A9e?= X-Patchwork-Id: 139862 Delivered-To: patch@linaro.org Received: by 2002:a2e:970d:0:0:0:0:0 with SMTP id r13-v6csp4164370lji; Mon, 25 Jun 2018 09:05:15 -0700 (PDT) X-Google-Smtp-Source: AAOMgpeo/z3QrzI0H3kF0wJ0+TeV0Rtr7FWXDtZm5p58Ur3UEy696t8y1CEmdTU7BLMYc23zLpAl X-Received: by 2002:aed:220e:: with SMTP id n14-v6mr11444782qtc.68.1529942715318; Mon, 25 Jun 2018 09:05:15 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1529942715; cv=none; d=google.com; s=arc-20160816; b=iHXCT+UccNXyDqFG0kbJoY4+DTmvKUtviXFIYck+z1TltllzXn2n1ZS/xEL73dM1Fw Du99AeI4ZzVc3chanTulKzP/Br1KQfi/gVLK87SoVmsitMVblRM6D42Pa+5oL0BEe3IU 07rMakyx6eJxWSLxi/Iji2bJ/r8da7B3NERhBbXsflRcY6LOHySJrQ4eg9GhIefBEWLy eFWOhgAz7g2qJjmPjVeGp2YhRBSCVhiwhhkTPoeFFMwBPA7BXvb+cEpesfIK7/EHOqws k+NBJ/2AwqGvXZoqW/9CY+srSqI37+3dNYs9k2whOXWi4dYwjDs7mqRDcMGBy0NelJul /SJg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=sender:errors-to:cc:list-subscribe:list-help:list-post:list-archive :list-unsubscribe:list-id:precedence:subject :content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:to:from:dkim-signature:arc-authentication-results; bh=wvvefg7SIN2MnLMPoNxKILPy8nFjsmp3rK/nOlMAARw=; b=f7EMwCbyi1ExFg+iJaWp0qNHC0PF7hTv9HzkP8TUrAaEb84dxvPUCwSxWAoZoDr162 T9JsmxtgU6QoQwF3lqcCsFlq+InJHekY7enNn0cdwJKvtNyN4BczLeAckEeRCHyY5qr3 y+BdFvZYf8Iz6gig7WhuuWnBPnbq4ZNQ1VXoUYkJGLlU/3tNcivI5Zb78X5Czzo+KI4H W8sGjK58VXyWWU+qNbYfxUZzDxDolS7xskXQakVdgmo0kcMgoGMAQ9BUaTt27+KErZtV mXKuydxgpKDS2lTGQnL3VfVmKoP5b3s/9si4jGnCJGd7zGYpGU3BjeRaOEBM9wxkI1GG S87w== ARC-Authentication-Results: i=1; mx.google.com; dkim=fail header.i=@linaro.org header.s=google header.b=aFqFkmhr; spf=pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 2001:4830:134:3::11 as permitted sender) smtp.mailfrom="qemu-devel-bounces+patch=linaro.org@nongnu.org"; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=linaro.org Return-Path: Received: from lists.gnu.org (lists.gnu.org. [2001:4830:134:3::11]) by mx.google.com with ESMTPS id g3-v6si376250qve.248.2018.06.25.09.05.14 for (version=TLS1 cipher=AES128-SHA bits=128/128); Mon, 25 Jun 2018 09:05:15 -0700 (PDT) Received-SPF: pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 2001:4830:134:3::11 as permitted sender) client-ip=2001:4830:134:3::11; Authentication-Results: mx.google.com; dkim=fail header.i=@linaro.org header.s=google header.b=aFqFkmhr; spf=pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 2001:4830:134:3::11 as permitted sender) smtp.mailfrom="qemu-devel-bounces+patch=linaro.org@nongnu.org"; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=linaro.org Received: from localhost ([::1]:48022 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1fXTzO-0000GN-El for patch@linaro.org; Mon, 25 Jun 2018 12:05:14 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:52851) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1fXTub-0004yp-NM for qemu-devel@nongnu.org; Mon, 25 Jun 2018 12:00:19 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1fXTua-00055E-Gg for qemu-devel@nongnu.org; Mon, 25 Jun 2018 12:00:17 -0400 Received: from mail-wm0-x241.google.com ([2a00:1450:400c:c09::241]:38673) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1fXTua-000548-A2 for qemu-devel@nongnu.org; Mon, 25 Jun 2018 12:00:16 -0400 Received: by mail-wm0-x241.google.com with SMTP id 69-v6so10601310wmf.3 for ; Mon, 25 Jun 2018 09:00:16 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=wvvefg7SIN2MnLMPoNxKILPy8nFjsmp3rK/nOlMAARw=; b=aFqFkmhrxA/evWFvhHeb9/z1tCAfvGS3uhMYtVo16y+Qi4zZYx+Pi1CmFLvuMerWHh 6OqYpGl/gITolD0tEGRHC88lPu6f/kFG72tIswl9oCb1o7jwyVhkVrise6uTwoIjhSts 9oHG0pXnbVUUKw4lduhsqzWc7LmmE+MR2iRUo= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=wvvefg7SIN2MnLMPoNxKILPy8nFjsmp3rK/nOlMAARw=; b=llW7MtpVgfVYzv8omXnZyyqcx+HxLA/JxXT8C+E3xO8Ca9hu4jJF1x8sMyKCiQhXkB AW4VOtHkfnFR8ta9cjFnW/QdCzAWHzx4WakYP97GOFPjFf7uA9E/8WiNP1ZJFeAVGJl9 BU0u4bn7y/lfOQvobOjiBAaPMjw/h7uMuDhgQdnlKIbN0NtNhGahI7K+RK+5+mIReBB0 77YL75FRmm1SIDCxYLqsmlltI6d0UPaXfFl02NXlKtsxWHN7uUfbRO5OQKc1JJRACEpN oEqyjLamwvNPd77HvtFUt7nDTcC4YwBr244LQq78G71F42ISxYPT5I2RH9DN0xrDh3SX /dDQ== X-Gm-Message-State: APt69E0c9+YYgDtgjc5F0iW/7IWO1FhPvn4cQMw/8C7h/p6DNK739bZR qdvLovYotHtaSWUIvrw1X/VFaw== X-Received: by 2002:a1c:8c55:: with SMTP id o82-v6mr1420668wmd.60.1529942415020; Mon, 25 Jun 2018 09:00:15 -0700 (PDT) Received: from zen.linaro.local ([81.128.185.34]) by smtp.gmail.com with ESMTPSA id a9-v6sm12494479wmh.38.2018.06.25.09.00.10 (version=TLS1_2 cipher=ECDHE-RSA-CHACHA20-POLY1305 bits=256/256); Mon, 25 Jun 2018 09:00:12 -0700 (PDT) Received: from zen.linaroharston (localhost [127.0.0.1]) by zen.linaro.local (Postfix) with ESMTP id 99D6E3E08E5; Mon, 25 Jun 2018 17:00:09 +0100 (BST) From: =?utf-8?q?Alex_Benn=C3=A9e?= To: peter.maydell@linaro.org Date: Mon, 25 Jun 2018 17:00:09 +0100 Message-Id: <20180625160009.17437-6-alex.bennee@linaro.org> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20180625160009.17437-1-alex.bennee@linaro.org> References: <20180625160009.17437-1-alex.bennee@linaro.org> MIME-Version: 1.0 X-detected-operating-system: by eggs.gnu.org: Genre and OS details not recognized. X-Received-From: 2a00:1450:400c:c09::241 Subject: [Qemu-devel] [PATCH v3 5/5] tests/tcg/aarch64: userspace system register test X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: qemu-arm@nongnu.org, =?utf-8?q?Alex_Benn=C3=A9e?= , qemu-devel@nongnu.org Errors-To: qemu-devel-bounces+patch=linaro.org@nongnu.org Sender: "Qemu-devel" This tests a bunch of registers that the kernel allows userspace to read including the CPUID registers. Signed-off-by: Alex Bennée --- tests/tcg/aarch64/Makefile.target | 2 +- tests/tcg/aarch64/sysregs.c | 99 +++++++++++++++++++++++++++++++ 2 files changed, 100 insertions(+), 1 deletion(-) create mode 100644 tests/tcg/aarch64/sysregs.c -- 2.17.1 Reviewed-by: Richard Henderson diff --git a/tests/tcg/aarch64/Makefile.target b/tests/tcg/aarch64/Makefile.target index 08c45b8470..cc1a7eb486 100644 --- a/tests/tcg/aarch64/Makefile.target +++ b/tests/tcg/aarch64/Makefile.target @@ -7,7 +7,7 @@ VPATH += $(AARCH64_SRC) # we don't build any of the ARM tests AARCH64_TESTS=$(filter-out $(ARM_TESTS), $(TESTS)) -AARCH64_TESTS+=fcvt +AARCH64_TESTS+=fcvt sysregs TESTS:=$(AARCH64_TESTS) fcvt: LDFLAGS+=-lm diff --git a/tests/tcg/aarch64/sysregs.c b/tests/tcg/aarch64/sysregs.c new file mode 100644 index 0000000000..177d1fe33b --- /dev/null +++ b/tests/tcg/aarch64/sysregs.c @@ -0,0 +1,99 @@ +/* + * Check emulated system register access for linux-user mode. + * + * See: https://www.kernel.org/doc/Documentation/arm64/cpu-feature-registers.txt + */ + +#include +#include +#include +#include +#include +#include + +#define get_cpu_reg(id) ({ \ + unsigned long __val = 0xdeadbeef; \ + asm("mrs %0, "#id : "=r" (__val)); \ + printf("%-20s: 0x%016lx\n", #id, __val); \ + }) + +bool should_fail; + +int should_fail_count; +int should_not_fail_count; +uintptr_t failed_pc[10]; + +void sigill_handler(int signo, siginfo_t *si, void *data) +{ + ucontext_t *uc = (ucontext_t *)data; + + if (should_fail) { + should_fail_count++; + } else { + uintptr_t pc = (uintptr_t) uc->uc_mcontext.pc; + failed_pc[should_not_fail_count++] = pc; + } + uc->uc_mcontext.pc += 4; +} + +int main(void) +{ + struct sigaction sa; + + /* Hook in a SIGILL handler */ + memset(&sa, 0, sizeof(struct sigaction)); + sa.sa_flags = SA_SIGINFO; + sa.sa_sigaction = &sigill_handler; + sigemptyset(&sa.sa_mask); + + if (sigaction(SIGILL, &sa, 0) != 0) { + perror("sigaction"); + return 1; + } + + /* since 4.12 */ + printf("Checking CNT registers\n"); + + get_cpu_reg(ctr_el0); + get_cpu_reg(cntvct_el0); + get_cpu_reg(cntfrq_el0); + + /* when (getauxval(AT_HWCAP) & HWCAP_CPUID), since 4.11*/ + if (!(getauxval(AT_HWCAP) & HWCAP_CPUID)) { + printf("CPUID registers unavailable\n"); + return 1; + } else { + printf("Checking CPUID registers\n"); + } + + get_cpu_reg(id_aa64isar0_el1); + get_cpu_reg(id_aa64isar1_el1); + get_cpu_reg(id_aa64mmfr0_el1); + get_cpu_reg(id_aa64mmfr1_el1); + get_cpu_reg(id_aa64pfr0_el1); + get_cpu_reg(id_aa64pfr1_el1); + get_cpu_reg(id_aa64dfr0_el1); + get_cpu_reg(id_aa64dfr1_el1); + + get_cpu_reg(midr_el1); + get_cpu_reg(mpidr_el1); + get_cpu_reg(revidr_el1); + + printf("Remaining registers should fail\n"); + should_fail = true; + + /* Unexposed register access causes SIGILL */ + get_cpu_reg(id_mmfr0_el1); + + if (should_not_fail_count > 0) { + int i; + for (i = 0; i < should_not_fail_count; i++) { + uintptr_t pc = failed_pc[i]; + uint32_t insn = *(uint32_t *) pc; + printf("insn %#x @ %#lx unexpected FAIL\n", insn, pc); + } + return 1; + } + + return should_fail_count == 1 ? 0 : 1; +}