From patchwork Mon Jun 25 16:00:07 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: 139865 Delivered-To: patch@linaro.org Received: by 2002:a2e:970d:0:0:0:0:0 with SMTP id r13-v6csp4170593lji; Mon, 25 Jun 2018 09:10:50 -0700 (PDT) X-Google-Smtp-Source: ADUXVKJ6YBNTGklh3/3XUp5BAWUC+a59nyAghTqPySCq6yRIrUukmXHBWzW0wcp4B3mbOPztpmqy X-Received: by 2002:aed:35c2:: with SMTP id d2-v6mr5742000qte.219.1529943050545; Mon, 25 Jun 2018 09:10:50 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1529943050; cv=none; d=google.com; s=arc-20160816; b=vELORE1lQ82k7Ax28aA1zt3BqbwK1UaDznPpoxMXfPZqzbE8DxOsVdoZnhKaUtMsSp CzaK9k2x5bABFmm+0D5uI+n4TmXN76EprxSRnZ5ulb5y8DtDO4BjNHutKcrBnTiU3ONB 8vB0Ijp5m/IrUVPyaq8Lxeh50wRrms5pmnruTrbbvgD6vG3I1oZA45n/t73BxrO61zbK k+hWgBHlxMPlQU+khloZOVb0QiOzjoBI88DxAu9W6yCJ+haerKmPB7qSz2A772/W1y26 J3n91STajzLdSuvjFkebK4L6U4CqK6VdtDpnQQw+pcHeL86epgvy0Gv/Jf8lj1crkn9p TFNg== 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=L+CkdW7090xExY/8k1283u40u9PL7caTx+GsyIIpY34=; b=Nw/tqbko9pxltLmtIa23Qx9n7uOda4ZFd1l/Ag5Q+CP1TjTDcM9f9XuzwYHjnNr5rM QGEPmc2epYYmv/0pzDbH3tUQkRf47ZzobBbWIUTKKQrpIgQT7gFMBACexVCSQ+BtSi5J Rq391kjjd0s47OCxzul5742LQdYnnlbAxfMa8ErSu7Y6UzCjHoOXh66VUDd7s7vSJTcg TbkTkgmLdUYn9DZ+7ZTkzlPdfAlqj/GeO3CXs1ypNR/JXkO3fgnM/sfHWgNDVKk7O/W2 heWuWm8idT12tkRqE9YB8cuGGmNfBOmFejedSi44Euua+lNPcHiw49WIP9/omGUqtteG tmCw== ARC-Authentication-Results: i=1; mx.google.com; dkim=fail header.i=@linaro.org header.s=google header.b=Qz6tS6f+; 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 o3-v6si3288090qkc.17.2018.06.25.09.10.50 for (version=TLS1 cipher=AES128-SHA bits=128/128); Mon, 25 Jun 2018 09:10:50 -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=Qz6tS6f+; 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]:48087 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1fXU4n-00055V-H2 for patch@linaro.org; Mon, 25 Jun 2018 12:10:49 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:52904) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1fXTue-000594-Me for qemu-devel@nongnu.org; Mon, 25 Jun 2018 12:00:24 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1fXTuY-00052w-Bs for qemu-devel@nongnu.org; Mon, 25 Jun 2018 12:00:20 -0400 Received: from mail-wm0-x244.google.com ([2a00:1450:400c:c09::244]:34671) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1fXTuY-00051r-2X for qemu-devel@nongnu.org; Mon, 25 Jun 2018 12:00:14 -0400 Received: by mail-wm0-x244.google.com with SMTP id l15-v6so12870413wmc.1 for ; Mon, 25 Jun 2018 09:00:13 -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=L+CkdW7090xExY/8k1283u40u9PL7caTx+GsyIIpY34=; b=Qz6tS6f+YHXESmgV5zWpIt0Uflvre60u516aFmi8/gBa21en0pLzJUn2Zr5fFAUXal 26VXYvfWwGGSwFNO6Ea/H4uQ7oQeFy4+yRE23uTDGqUaglRwAcMiG8paxh4/RTfPAcqZ /Pt/UTxOnGztd8jKvWp9QgYOqKOn8/scGQ6Cc= 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=L+CkdW7090xExY/8k1283u40u9PL7caTx+GsyIIpY34=; b=WptKY1EwgjwQO3YfVeOQvPZd3xGrKn6cn7FtQT+DXvLZnh87tgzhe7JmPSP2f136Ro z5hDLMspaC0gZVxHfx6WKNfVRXiqdM6ZdQFwTo/TiJXst6V0apZG/us+V2B63gsQD0j/ h+jTXwoVr0b8SGqn410Crx9KPF1x3ZpdP3jRC9XRDB0j21KeTOZeMcNBtjjxyJWNEyMG 2vaVuxYysq/SZ5olehvqz0v8QyBFSbqPps8jdReKOKJ3mdaLoYe4VCYSYQ3nb0af7naz DUydvCBzF7sU78GVXIr8LX0Hz+TKgGrybc53aEExfY1DXEK5Qh9Rxp2TXd37769dMIrk I7rQ== X-Gm-Message-State: APt69E2mbVd4UETIzzM5JsRvicwSsTX2rZ2K5nsYt16SkxG3EuS427ZE xF2OPjssTVymyFfmeB8xEWrl3w== X-Received: by 2002:a1c:8cc8:: with SMTP id o191-v6mr1497881wmd.75.1529942412926; Mon, 25 Jun 2018 09:00:12 -0700 (PDT) Received: from zen.linaro.local ([81.128.185.34]) by smtp.gmail.com with ESMTPSA id l67-v6sm12841639wmb.22.2018.06.25.09.00.09 (version=TLS1_2 cipher=ECDHE-RSA-CHACHA20-POLY1305 bits=256/256); Mon, 25 Jun 2018 09:00:11 -0700 (PDT) Received: from zen.linaroharston (localhost [127.0.0.1]) by zen.linaro.local (Postfix) with ESMTP id 7277B3E08BB; 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:07 +0100 Message-Id: <20180625160009.17437-4-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::244 Subject: [Qemu-devel] [PATCH v3 3/5] target/arm: expose CPUID registers to userspace 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" A number of CPUID registers are exposed to userspace by modern Linux kernels thanks to the "ARM64 CPU Feature Registers" ABI. For CONFIG_USER_ONLY we don't emulate the kernels trap and emulate but instead just lower the read permission to PL0_R (hidden behind the PL1U_R macro). The ID_AA64PFR0_EL1 is a little special as the GIC version is hidden from userspace so we can define a ARM_CP_CONST version of the register for usermode. Signed-off-by: Alex Bennée squash! target/arm: expose CPUID registers to userspace --- target/arm/cpu.h | 7 +++++++ target/arm/helper.c | 39 +++++++++++++++++++++++++-------------- 2 files changed, 32 insertions(+), 14 deletions(-) -- 2.17.1 diff --git a/target/arm/cpu.h b/target/arm/cpu.h index a4507a2d6f..156c811654 100644 --- a/target/arm/cpu.h +++ b/target/arm/cpu.h @@ -1924,6 +1924,13 @@ static inline bool cptype_valid(int cptype) #define PL0_R (0x02 | PL1_R) #define PL0_W (0x01 | PL1_W) +/* for AArch64 HWCAP_CPUID to userspace */ +#ifdef CONFIG_USER_ONLY +#define PL1U_R PL0_R +#else +#define PL1U_R PL1_R +#endif + #define PL3_RW (PL3_R | PL3_W) #define PL2_RW (PL2_R | PL2_W) #define PL1_RW (PL1_R | PL1_W) diff --git a/target/arm/helper.c b/target/arm/helper.c index 9d81feb124..1ea0dc4593 100644 --- a/target/arm/helper.c +++ b/target/arm/helper.c @@ -2987,7 +2987,7 @@ static uint64_t mpidr_read(CPUARMState *env, const ARMCPRegInfo *ri) static const ARMCPRegInfo mpidr_cp_reginfo[] = { { .name = "MPIDR", .state = ARM_CP_STATE_BOTH, .opc0 = 3, .crn = 0, .crm = 0, .opc1 = 0, .opc2 = 5, - .access = PL1_R, .readfn = mpidr_read, .type = ARM_CP_NO_RAW }, + .access = PL1U_R, .readfn = mpidr_read, .type = ARM_CP_NO_RAW }, REGINFO_SENTINEL }; @@ -4776,6 +4776,7 @@ static uint64_t id_pfr1_read(CPUARMState *env, const ARMCPRegInfo *ri) return pfr1; } +#ifndef CONFIG_USER_ONLY static uint64_t id_aa64pfr0_read(CPUARMState *env, const ARMCPRegInfo *ri) { ARMCPU *cpu = arm_env_get_cpu(env); @@ -4786,6 +4787,7 @@ static uint64_t id_aa64pfr0_read(CPUARMState *env, const ARMCPRegInfo *ri) } return pfr0; } +#endif void register_cp_regs_for_features(ARMCPU *cpu) { @@ -4934,18 +4936,26 @@ void register_cp_regs_for_features(ARMCPU *cpu) * define new registers here. */ ARMCPRegInfo v8_idregs[] = { - /* ID_AA64PFR0_EL1 is not a plain ARM_CP_CONST because we don't - * know the right value for the GIC field until after we - * define these regs. + /* ID_AA64PFR0_EL1 is not a plain ARM_CP_CONST for system + * emulation because we don't know the right value for the + * GIC field until after we define these regs. For + * user-mode HWCAP_CPUID emulation the gic bits are masked + * anyway. */ { .name = "ID_AA64PFR0_EL1", .state = ARM_CP_STATE_AA64, .opc0 = 3, .opc1 = 0, .crn = 0, .crm = 4, .opc2 = 0, +#ifndef CONFIG_USER_ONLY .access = PL1_R, .type = ARM_CP_NO_RAW, .readfn = id_aa64pfr0_read, - .writefn = arm_cp_write_ignore }, + .writefn = arm_cp_write_ignore +#else + .access = PL0_R, .type = ARM_CP_CONST, + .resetvalue = cpu->id_aa64pfr0 +#endif + }, { .name = "ID_AA64PFR1_EL1", .state = ARM_CP_STATE_AA64, .opc0 = 3, .opc1 = 0, .crn = 0, .crm = 4, .opc2 = 1, - .access = PL1_R, .type = ARM_CP_CONST, + .access = PL1U_R, .type = ARM_CP_CONST, .resetvalue = cpu->id_aa64pfr1}, { .name = "ID_AA64PFR2_EL1_RESERVED", .state = ARM_CP_STATE_AA64, .opc0 = 3, .opc1 = 0, .crn = 0, .crm = 4, .opc2 = 2, @@ -4973,11 +4983,11 @@ void register_cp_regs_for_features(ARMCPU *cpu) .resetvalue = 0 }, { .name = "ID_AA64DFR0_EL1", .state = ARM_CP_STATE_AA64, .opc0 = 3, .opc1 = 0, .crn = 0, .crm = 5, .opc2 = 0, - .access = PL1_R, .type = ARM_CP_CONST, + .access = PL1U_R, .type = ARM_CP_CONST, .resetvalue = cpu->id_aa64dfr0 }, { .name = "ID_AA64DFR1_EL1", .state = ARM_CP_STATE_AA64, .opc0 = 3, .opc1 = 0, .crn = 0, .crm = 5, .opc2 = 1, - .access = PL1_R, .type = ARM_CP_CONST, + .access = PL1U_R, .type = ARM_CP_CONST, .resetvalue = cpu->id_aa64dfr1 }, { .name = "ID_AA64DFR2_EL1_RESERVED", .state = ARM_CP_STATE_AA64, .opc0 = 3, .opc1 = 0, .crn = 0, .crm = 5, .opc2 = 2, @@ -5005,11 +5015,11 @@ void register_cp_regs_for_features(ARMCPU *cpu) .resetvalue = 0 }, { .name = "ID_AA64ISAR0_EL1", .state = ARM_CP_STATE_AA64, .opc0 = 3, .opc1 = 0, .crn = 0, .crm = 6, .opc2 = 0, - .access = PL1_R, .type = ARM_CP_CONST, + .access = PL1U_R, .type = ARM_CP_CONST, .resetvalue = cpu->id_aa64isar0 }, { .name = "ID_AA64ISAR1_EL1", .state = ARM_CP_STATE_AA64, .opc0 = 3, .opc1 = 0, .crn = 0, .crm = 6, .opc2 = 1, - .access = PL1_R, .type = ARM_CP_CONST, + .access = PL1U_R, .type = ARM_CP_CONST, .resetvalue = cpu->id_aa64isar1 }, { .name = "ID_AA64ISAR2_EL1_RESERVED", .state = ARM_CP_STATE_AA64, .opc0 = 3, .opc1 = 0, .crn = 0, .crm = 6, .opc2 = 2, @@ -5037,11 +5047,11 @@ void register_cp_regs_for_features(ARMCPU *cpu) .resetvalue = 0 }, { .name = "ID_AA64MMFR0_EL1", .state = ARM_CP_STATE_AA64, .opc0 = 3, .opc1 = 0, .crn = 0, .crm = 7, .opc2 = 0, - .access = PL1_R, .type = ARM_CP_CONST, + .access = PL1U_R, .type = ARM_CP_CONST, .resetvalue = cpu->id_aa64mmfr0 }, { .name = "ID_AA64MMFR1_EL1", .state = ARM_CP_STATE_AA64, .opc0 = 3, .opc1 = 0, .crn = 0, .crm = 7, .opc2 = 1, - .access = PL1_R, .type = ARM_CP_CONST, + .access = PL1U_R, .type = ARM_CP_CONST, .resetvalue = cpu->id_aa64mmfr1 }, { .name = "ID_AA64MMFR2_EL1_RESERVED", .state = ARM_CP_STATE_AA64, .opc0 = 3, .opc1 = 0, .crn = 0, .crm = 7, .opc2 = 2, @@ -5335,7 +5345,7 @@ void register_cp_regs_for_features(ARMCPU *cpu) ARMCPRegInfo id_v8_midr_cp_reginfo[] = { { .name = "MIDR_EL1", .state = ARM_CP_STATE_BOTH, .opc0 = 3, .opc1 = 0, .crn = 0, .crm = 0, .opc2 = 0, - .access = PL1_R, .type = ARM_CP_NO_RAW, .resetvalue = cpu->midr, + .access = PL1U_R, .type = ARM_CP_NO_RAW, .resetvalue = cpu->midr, .fieldoffset = offsetof(CPUARMState, cp15.c0_cpuid), .readfn = midr_read }, /* crn = 0 op1 = 0 crm = 0 op2 = 4,7 : AArch32 aliases of MIDR */ @@ -5347,7 +5357,8 @@ void register_cp_regs_for_features(ARMCPU *cpu) .access = PL1_R, .resetvalue = cpu->midr }, { .name = "REVIDR_EL1", .state = ARM_CP_STATE_BOTH, .opc0 = 3, .opc1 = 0, .crn = 0, .crm = 0, .opc2 = 6, - .access = PL1_R, .type = ARM_CP_CONST, .resetvalue = cpu->revidr }, + .access = PL1U_R, .type = ARM_CP_CONST, + .resetvalue = cpu->revidr }, REGINFO_SENTINEL }; ARMCPRegInfo id_cp_reginfo[] = {