From patchwork Tue Mar 12 16:19:03 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Richard Henderson X-Patchwork-Id: 160135 Delivered-To: patch@linaro.org Received: by 2002:a02:5cc1:0:0:0:0:0 with SMTP id w62csp13336363jad; Tue, 12 Mar 2019 10:04:04 -0700 (PDT) X-Google-Smtp-Source: APXvYqzAhvxX/jC4Hw4nN6Sk9MgTbcLMRMyAXa4byRc9DD/L19c3LI5cLp3rqdU+UZoL63PKxe0t X-Received: by 2002:a81:5503:: with SMTP id j3mr31209386ywb.355.1552410244224; Tue, 12 Mar 2019 10:04:04 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1552410244; cv=none; d=google.com; s=arc-20160816; b=mnOW+51y9c2xOk1MIqFdlYBQcTrz2mLyxfFCjQ4M/ts3ldfy9mEDUqzseHr7kXcQUx xnDmDfoLRvxR+UFwOKUcuMUDHCVZnR8ZlnaB+javImDFgxVKr5vTNNmg1neydP2uQyQA KqTau6Ydk0Mq49vbh/nzgoyIGK6BsS/Gs+qeoOHj2GsD9c4EQKyx9MHwo7mHB4RGStRo Zet4q6OapCyNyzQgE6RzSXuVHISYi4Szzn8yam4k4YAiq1/1Lj9B8zC8PT4Nsoz6X7nm mO6RL2VH6gvhQ2m6dWQXQF5m8dhUo8upzMNb1QiY9e8OfiAB6dXjTzo43iXZZYHWWdyT KR0g== 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:references:in-reply-to :message-id:date:to:from:dkim-signature; bh=2R2HF6vZiOsEmaQiHzoXBMfK3k9K0ilofjjPdJHUkAY=; b=M9SpDlWF2rRFTXK3gLQBZOZnwdLG8wUnok+pBELE2c59kqbztjiIAlyIniAaZCus8f 4bgjX46AD0S1HX6vxcDYcp9P2SoO1WWr7mBFD/FMNzN/jJErZRw/wgqeYqvBBUcDDS2X 2bcpmk8CoZCnS819Io1Rtm0qKu0+63AWwtAF7IPcgyDLRWLJvzipvKo4EeYT1+XFqxRo hRDlSa1yBS/1TEoB9KH/t9OOgc1gutdbZbVph0DUYqO6pAiK6pvcDJKUmLbaeOu71IX3 QOly2UQIAJrVj2nFfOmnl9bm+QHZLckJhNf/oMeHkMq/hY04cpUoY2QokwXkKfaatsXm FM2A== ARC-Authentication-Results: i=1; mx.google.com; dkim=fail header.i=@linaro.org header.s=google header.b=x5JkhasH; spf=pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 209.51.188.17 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. [209.51.188.17]) by mx.google.com with ESMTPS id 126si5093284ybv.310.2019.03.12.10.04.04 for (version=TLS1 cipher=AES128-SHA bits=128/128); Tue, 12 Mar 2019 10:04:04 -0700 (PDT) Received-SPF: pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; Authentication-Results: mx.google.com; dkim=fail header.i=@linaro.org header.s=google header.b=x5JkhasH; spf=pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 209.51.188.17 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 ([127.0.0.1]:55966 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1h3kot-0002BO-Kw for patch@linaro.org; Tue, 12 Mar 2019 13:04:03 -0400 Received: from eggs.gnu.org ([209.51.188.92]:36769) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1h3k7u-0006C7-HG for qemu-devel@nongnu.org; Tue, 12 Mar 2019 12:19:39 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1h3k7o-00044X-RI for qemu-devel@nongnu.org; Tue, 12 Mar 2019 12:19:35 -0400 Received: from mail-pg1-x52e.google.com ([2607:f8b0:4864:20::52e]:38149) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1h3k7j-0003xG-Ax for qemu-devel@nongnu.org; Tue, 12 Mar 2019 12:19:29 -0400 Received: by mail-pg1-x52e.google.com with SMTP id m2so2195652pgl.5 for ; Tue, 12 Mar 2019 09:19:22 -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; bh=2R2HF6vZiOsEmaQiHzoXBMfK3k9K0ilofjjPdJHUkAY=; b=x5JkhasH1VeZnH9xOSFS5mH+ZqZxD4xG257M5+Q1Wy3N6ARfJ93UsAd6grUdQ3x3Pm gBojahRZxBtM1fYPNlHP+M3oFp+Ob6weWi/fMsQNrb6/GQVtaJGtRfa71s4ycQzVU71X LeEyQwPXXX+g4Dqd1twPlBnK9vlYRDiEhwOvW8/zOmMi4LuDPdEQwCY/AWYSpfJIN/jA gPCJA+U9WBuzV4QsQDRPA6u7+pW8ytjgRppiUjTMJPnVhdwKR7XvHMDOo9pB+In5wHLY kOixeobGxz3Y/drTMs5nRtK8BwSmojiEjmAEVRF3DgvcF+1ZqptPzP5t42lpibDefRMx 88fg== 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; bh=2R2HF6vZiOsEmaQiHzoXBMfK3k9K0ilofjjPdJHUkAY=; b=SwW+kHbJyMtL6AFHIffXpAHgKf9FXAgWhRZ7ej42R02LPvqx3/0k74Fd2VtJoF83b0 yzz2W6IO1HS1x5LaosEIN2zysxhs5IX1LiO19b961gDfFqQHwKVrEuxqnq+whMpmLboZ IdwE8B6zGfmf38HW3xOSXPnpdPAu6FK6Q2dus5yp+bmSRqEjag12t8UKZ5mlBqk6pjdJ o5n4jgjFTZUcm21U0F+BN1Ob+3N4lXgCOq0/QgYcC3M/Y4LJi+ygP2a8cVRTyATWmIGL qnISzJvxOVTxAPuRKxEP+bMRKr35X5xqNNkGcu4yG0ZIkBevJjR7Km1Kce2aZj/Bfy5P pz9g== X-Gm-Message-State: APjAAAUNHRbAYlMSEJEFY8j6sludc+8j0sOkCg4iS4r/3oRor5AJsRuG XE1BSVkRCTzOtl8tvsszEDFtmgnc4Bg= X-Received: by 2002:a65:5303:: with SMTP id m3mr35477544pgq.292.1552407561044; Tue, 12 Mar 2019 09:19:21 -0700 (PDT) Received: from cloudburst.twiddle.net (97-113-188-82.tukw.qwest.net. [97.113.188.82]) by smtp.gmail.com with ESMTPSA id q62sm12605644pga.32.2019.03.12.09.19.19 (version=TLS1_2 cipher=ECDHE-RSA-CHACHA20-POLY1305 bits=256/256); Tue, 12 Mar 2019 09:19:20 -0700 (PDT) From: Richard Henderson To: qemu-devel@nongnu.org Date: Tue, 12 Mar 2019 09:19:03 -0700 Message-Id: <20190312161904.31130-11-richard.henderson@linaro.org> X-Mailer: git-send-email 2.17.2 In-Reply-To: <20190312161904.31130-1-richard.henderson@linaro.org> References: <20190312161904.31130-1-richard.henderson@linaro.org> X-detected-operating-system: by eggs.gnu.org: Genre and OS details not recognized. X-Received-From: 2607:f8b0:4864:20::52e Subject: [Qemu-devel] [PULL 10/11] target/hppa: add TLB protection id check 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: peter.maydell@linaro.org, Sven Schnelle Errors-To: qemu-devel-bounces+patch=linaro.org@nongnu.org Sender: "Qemu-devel" From: Sven Schnelle Signed-off-by: Sven Schnelle Message-Id: <20190311191602.25796-10-svens@stackframe.org> [rth: Add required tlb flushing when prot id registers change.] Signed-off-by: Richard Henderson --- target/hppa/cpu.h | 10 ++++++++++ target/hppa/helper.h | 1 + target/hppa/gdbstub.c | 20 ++++++++++++-------- target/hppa/helper.c | 10 ++++++++++ target/hppa/mem_helper.c | 28 +++++++++++++++++++++++++++- target/hppa/translate.c | 10 ++++++++++ 6 files changed, 70 insertions(+), 9 deletions(-) -- 2.17.2 diff --git a/target/hppa/cpu.h b/target/hppa/cpu.h index 861bbb1f16..c062c7969c 100644 --- a/target/hppa/cpu.h +++ b/target/hppa/cpu.h @@ -143,6 +143,10 @@ #endif #define CR_RC 0 +#define CR_PID1 8 +#define CR_PID2 9 +#define CR_PID3 12 +#define CR_PID4 13 #define CR_SCRCCR 10 #define CR_SAR 11 #define CR_IVA 14 @@ -341,6 +345,12 @@ target_ureg cpu_hppa_get_psw(CPUHPPAState *env); void cpu_hppa_put_psw(CPUHPPAState *env, target_ureg); void cpu_hppa_loaded_fr0(CPUHPPAState *env); +#ifdef CONFIG_USER_ONLY +static inline void cpu_hppa_change_prot_id(CPUHPPAState *env) { } +#else +void cpu_hppa_change_prot_id(CPUHPPAState *env); +#endif + #define cpu_signal_handler cpu_hppa_signal_handler int cpu_hppa_signal_handler(int host_signum, void *pinfo, void *puc); diff --git a/target/hppa/helper.h b/target/hppa/helper.h index bfe0dd1db1..38d834ef6b 100644 --- a/target/hppa/helper.h +++ b/target/hppa/helper.h @@ -92,4 +92,5 @@ DEF_HELPER_FLAGS_3(itlbp, TCG_CALL_NO_RWG, void, env, tl, tr) DEF_HELPER_FLAGS_2(ptlb, TCG_CALL_NO_RWG, void, env, tl) DEF_HELPER_FLAGS_1(ptlbe, TCG_CALL_NO_RWG, void, env) DEF_HELPER_FLAGS_2(lpa, TCG_CALL_NO_WG, tr, env, tl) +DEF_HELPER_FLAGS_1(change_prot_id, TCG_CALL_NO_RWG, void, env) #endif diff --git a/target/hppa/gdbstub.c b/target/hppa/gdbstub.c index 3157a690f2..983bf92aaf 100644 --- a/target/hppa/gdbstub.c +++ b/target/hppa/gdbstub.c @@ -93,19 +93,19 @@ int hppa_cpu_gdb_read_register(CPUState *cs, uint8_t *mem_buf, int n) val = env->cr[CR_RC]; break; case 52: - val = env->cr[8]; + val = env->cr[CR_PID1]; break; case 53: - val = env->cr[9]; + val = env->cr[CR_PID2]; break; case 54: val = env->cr[CR_SCRCCR]; break; case 55: - val = env->cr[12]; + val = env->cr[CR_PID3]; break; case 56: - val = env->cr[13]; + val = env->cr[CR_PID4]; break; case 57: val = env->cr[24]; @@ -224,19 +224,23 @@ int hppa_cpu_gdb_write_register(CPUState *cs, uint8_t *mem_buf, int n) env->cr[CR_RC] = val; break; case 52: - env->cr[8] = val; + env->cr[CR_PID1] = val; + cpu_hppa_change_prot_id(env); break; case 53: - env->cr[9] = val; + env->cr[CR_PID2] = val; + cpu_hppa_change_prot_id(env); break; case 54: env->cr[CR_SCRCCR] = val; break; case 55: - env->cr[12] = val; + env->cr[CR_PID3] = val; + cpu_hppa_change_prot_id(env); break; case 56: - env->cr[13] = val; + env->cr[CR_PID4] = val; + cpu_hppa_change_prot_id(env); break; case 57: env->cr[24] = val; diff --git a/target/hppa/helper.c b/target/hppa/helper.c index 6539061e52..ac750b62ef 100644 --- a/target/hppa/helper.c +++ b/target/hppa/helper.c @@ -21,6 +21,7 @@ #include "cpu.h" #include "fpu/softfloat.h" +#include "exec/exec-all.h" #include "exec/helper-proto.h" target_ureg cpu_hppa_get_psw(CPUHPPAState *env) @@ -49,6 +50,7 @@ target_ureg cpu_hppa_get_psw(CPUHPPAState *env) void cpu_hppa_put_psw(CPUHPPAState *env, target_ureg psw) { + target_ureg old_psw = env->psw; target_ureg cb = 0; env->psw = psw & ~(PSW_N | PSW_V | PSW_CB); @@ -64,6 +66,14 @@ void cpu_hppa_put_psw(CPUHPPAState *env, target_ureg psw) cb |= ((psw >> 9) & 1) << 8; cb |= ((psw >> 8) & 1) << 4; env->psw_cb = cb; + + /* If PSW_P changes, it affects how we translate addresses. */ + if ((psw ^ old_psw) & PSW_P) { +#ifndef CONFIG_USER_ONLY + CPUState *src = CPU(hppa_env_get_cpu(env)); + tlb_flush_by_mmuidx(src, 0xf); +#endif + } } void hppa_cpu_dump_state(CPUState *cs, FILE *f, diff --git a/target/hppa/mem_helper.c b/target/hppa/mem_helper.c index a69cca9c5d..c9b57d07c3 100644 --- a/target/hppa/mem_helper.c +++ b/target/hppa/mem_helper.c @@ -131,7 +131,20 @@ int hppa_get_physical_address(CPUHPPAState *env, vaddr addr, int mmu_idx, break; } - /* ??? Check PSW_P and ent->access_prot. This can remove PAGE_WRITE. */ + /* access_id == 0 means public page and no check is performed */ + if ((env->psw & PSW_P) && ent->access_id) { + /* If bits [31:1] match, and bit 0 is set, suppress write. */ + int match = ent->access_id * 2 + 1; + + if (match == env->cr[CR_PID1] || match == env->cr[CR_PID2] || + match == env->cr[CR_PID3] || match == env->cr[CR_PID4]) { + prot &= PAGE_READ | PAGE_EXEC; + if (type == PAGE_WRITE) { + ret = EXCP_DMPI; + goto egress; + } + } + } /* No guest access type indicates a non-architectural access from within QEMU. Bypass checks for access, D, B and T bits. */ @@ -334,6 +347,19 @@ void HELPER(ptlbe)(CPUHPPAState *env) tlb_flush_by_mmuidx(src, 0xf); } +void cpu_hppa_change_prot_id(CPUHPPAState *env) +{ + if (env->psw & PSW_P) { + CPUState *src = CPU(hppa_env_get_cpu(env)); + tlb_flush_by_mmuidx(src, 0xf); + } +} + +void HELPER(change_prot_id)(CPUHPPAState *env) +{ + cpu_hppa_change_prot_id(env); +} + target_ureg HELPER(lpa)(CPUHPPAState *env, target_ulong addr) { hwaddr phys; diff --git a/target/hppa/translate.c b/target/hppa/translate.c index 6ac196804b..70a7cd4a89 100644 --- a/target/hppa/translate.c +++ b/target/hppa/translate.c @@ -2256,6 +2256,16 @@ static bool trans_mtctl(DisasContext *ctx, arg_mtctl *a) offsetof(CPUHPPAState, cr_back[ctl - CR_IIASQ])); break; + case CR_PID1: + case CR_PID2: + case CR_PID3: + case CR_PID4: + tcg_gen_st_reg(reg, cpu_env, offsetof(CPUHPPAState, cr[ctl])); +#ifndef CONFIG_USER_ONLY + gen_helper_change_prot_id(cpu_env); +#endif + break; + default: tcg_gen_st_reg(reg, cpu_env, offsetof(CPUHPPAState, cr[ctl])); break;