From patchwork Sun Jan 28 23:15:00 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Richard Henderson X-Patchwork-Id: 126108 Delivered-To: patch@linaro.org Received: by 10.46.84.92 with SMTP id y28csp1982810ljd; Sun, 28 Jan 2018 15:34:04 -0800 (PST) X-Google-Smtp-Source: AH8x227RV90f63xmRBgATk7YtlQcDv5otpELbrV8nTMjJo7fMqMsNyVaT2blMoJtkIxWYykS5BN7 X-Received: by 10.37.135.79 with SMTP id e15mr15771368ybn.303.1517182444386; Sun, 28 Jan 2018 15:34:04 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1517182444; cv=none; d=google.com; s=arc-20160816; b=U8NDeUULvLyT81OTmGfWa1bOXB9zKprXr7sUlrUAkxkwWKKoDT+NPaS91EdWYD52gT /TsZ1TSKfVrNs3d9xSAU0QAO+r0gGF0FxEZYF9Xd1aflISf02EFLb8+iXxOJ0J7Zqfro OueWhchUZsi6BiutjRFPL/21PxPGVd+FHFFN7wSGUhltsfbXdqo1qySDP57SmoIZUVgN lVEC3hmdVSaBed/+f0RrWfXyIvbMJm+vpNRwuv0AEnMIiWO0fa9GbiCyWeg7CWsEhT/0 pj8769C63nEyqBivuYp/t4ATzB4798ywjRDDegrUx1DJtDVlHD2U/H/EfGOdMUXYTf4o 3kCg== 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=R7Enyxbsmc64EfsW5JScMt9UKiAW8/F8PsYnC3AJCUE=; b=IL5UePytEN9Hn6mWmQkViGYTEO/Sn+6lNe+jh4OJkNVRyze66YF9mCn05wKihL0KCd VrMbz3KS4hCGlp/ydiLnaRCmdY2bSSLm14N+w/GymccYDXukqVINVEdGJvZumUziy+bI GGeBTtS+3P7R0gGiQXDZcsEkStVXqc5RBSDajS6biwqmNE78CF+9W9iKzMSjkQDVrPIe 1CQuRNiBD9zS0FpeHwsSGySho3+wxqwemUM0uxZrh2NY/MWl/R1hr82E3bc5qvZahKme oSewXdwjJfiw24G3VwtLXoUqREi9CnAPOQTFHBYCUuLzvvsXy2FlPRs16+i/OR8eXjkJ AhMA== ARC-Authentication-Results: i=1; mx.google.com; dkim=fail header.i=@linaro.org header.s=google header.b=UEN+lcOS; 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 m63si4508264ybm.200.2018.01.28.15.34.04 for (version=TLS1 cipher=AES128-SHA bits=128/128); Sun, 28 Jan 2018 15:34:04 -0800 (PST) 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=UEN+lcOS; 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]:45011 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1efwSZ-0006sO-NJ for patch@linaro.org; Sun, 28 Jan 2018 18:34:03 -0500 Received: from eggs.gnu.org ([2001:4830:134:3::10]:52088) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1efwB6-0002m7-II for qemu-devel@nongnu.org; Sun, 28 Jan 2018 18:16:01 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1efwB2-0008PA-AA for qemu-devel@nongnu.org; Sun, 28 Jan 2018 18:16:00 -0500 Received: from mail-pf0-x243.google.com ([2607:f8b0:400e:c00::243]:38395) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1efwB2-0008OM-41 for qemu-devel@nongnu.org; Sun, 28 Jan 2018 18:15:56 -0500 Received: by mail-pf0-x243.google.com with SMTP id k19so3261076pfj.5 for ; Sun, 28 Jan 2018 15:15:56 -0800 (PST) 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=R7Enyxbsmc64EfsW5JScMt9UKiAW8/F8PsYnC3AJCUE=; b=UEN+lcOSlGeBMf/4UiillCzCol3OacLwG1rCliHvDWz2ewWCJzha9dvqP+MkToGK1i 3hga2lvT579EalgkW1KRwHhAO6Z/2xlN4QDKqxg4QXgFPa7aHxSn4zeU2w3PV7krRbn9 xuWLPCR7kKLNCeEWkAK10QHfwneDwl1hWGuhc= 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=R7Enyxbsmc64EfsW5JScMt9UKiAW8/F8PsYnC3AJCUE=; b=DSBLS5IWcChFC9YhGMrT9I5JtOm+eGZAELsjftMQby3gBGf89WW4jLCUMJL1G8szbr 8w5lXv1rKJAiaeEdXgwpw7R94t/hCuCLJ8XsGzmgdBbGP//L+1zCd7lIAsP2urXtIkOS lFcsjNIdlT7qftebpWRHwMAOqTTfUQxXFZX4R7V1wgtqDswOGdBk8gQ/ixl4G4kmfK/Z INpBrbwsQo+g+pj7wQ75mceNZtla6cnXYoooj11eeGWaDlaAb1OvNVQoa18ZEUbeHva6 29I8TSc/T5aMfel1h2/bRwAh5InItLTj1mCLv329Jb1Ye+cUc4OXSuQ1lMFpN8HTTjkv 0qqA== X-Gm-Message-State: AKwxyte5L1S8vpf/v1sDjcp0myRajT3Sf9KuhUPNm8xUKpA5sk+ilOGc aZdnxoKWADbcipF586Ubg6XxMFO3O+A= X-Received: by 2002:a17:902:622:: with SMTP id 31-v6mr19921136plg.448.1517181354868; Sun, 28 Jan 2018 15:15:54 -0800 (PST) Received: from cloudburst.twiddle.net (174-21-6-47.tukw.qwest.net. [174.21.6.47]) by smtp.gmail.com with ESMTPSA id r27sm26949344pfj.75.2018.01.28.15.15.53 (version=TLS1_2 cipher=ECDHE-RSA-CHACHA20-POLY1305 bits=256/256); Sun, 28 Jan 2018 15:15:54 -0800 (PST) From: Richard Henderson To: qemu-devel@nongnu.org Date: Sun, 28 Jan 2018 15:15:00 -0800 Message-Id: <20180128231528.22719-16-richard.henderson@linaro.org> X-Mailer: git-send-email 2.14.3 In-Reply-To: <20180128231528.22719-1-richard.henderson@linaro.org> References: <20180128231528.22719-1-richard.henderson@linaro.org> MIME-Version: 1.0 X-detected-operating-system: by eggs.gnu.org: Genre and OS details not recognized. X-Received-From: 2607:f8b0:400e:c00::243 Subject: [Qemu-devel] [PULL v4 15/43] target/hppa: Avoid privilege level decrease during branches 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 Errors-To: qemu-devel-bounces+patch=linaro.org@nongnu.org Sender: "Qemu-devel" These instructions force the destination privilege level of the branch destination to be no higher than current. Signed-off-by: Richard Henderson --- target/hppa/translate.c | 52 ++++++++++++++++++++++++++++++++++++++++++++----- 1 file changed, 47 insertions(+), 5 deletions(-) -- 2.14.3 diff --git a/target/hppa/translate.c b/target/hppa/translate.c index 6be9e0c3ff..4a69f05a91 100644 --- a/target/hppa/translate.c +++ b/target/hppa/translate.c @@ -1862,6 +1862,40 @@ static DisasJumpType do_ibranch(DisasContext *ctx, TCGv_reg dest, return DISAS_NEXT; } +/* Implement + * if (IAOQ_Front{30..31} < GR[b]{30..31}) + * IAOQ_Next{30..31} ← GR[b]{30..31}; + * else + * IAOQ_Next{30..31} ← IAOQ_Front{30..31}; + * which keeps the privilege level from being increased. + */ +static TCGv_reg do_ibranch_priv(DisasContext *ctx, TCGv_reg offset) +{ +#ifdef CONFIG_USER_ONLY + return offset; +#else + TCGv_reg dest; + switch (ctx->privilege) { + case 0: + /* Privilege 0 is maximum and is allowed to decrease. */ + return offset; + case 3: + /* Privilege 3 is minimum and is never allowed increase. */ + dest = get_temp(ctx); + tcg_gen_ori_reg(dest, offset, 3); + break; + default: + dest = tcg_temp_new(); + tcg_gen_andi_reg(dest, offset, -4); + tcg_gen_ori_reg(dest, dest, ctx->privilege); + tcg_gen_movcond_reg(TCG_COND_GTU, dest, dest, offset, dest, offset); + tcg_temp_free(dest); + break; + } + return dest; +#endif +} + #ifdef CONFIG_USER_ONLY /* On Linux, page zero is normally marked execute only + gateway. Therefore normal read or write is supposed to fail, but specific @@ -3441,6 +3475,7 @@ static DisasJumpType trans_be(DisasContext *ctx, uint32_t insn, bool is_l) unsigned n = extract32(insn, 1, 1); unsigned b = extract32(insn, 21, 5); target_sreg disp = assemble_17(insn); + TCGv_reg tmp; /* unsigned s = low_uextract(insn, 13, 3); */ /* ??? It seems like there should be a good way of using @@ -3449,16 +3484,19 @@ static DisasJumpType trans_be(DisasContext *ctx, uint32_t insn, bool is_l) manage along side branch delay slots. Therefore we handle entry into the gateway page via absolute address. */ +#ifdef CONFIG_USER_ONLY /* Since we don't implement spaces, just branch. Do notice the special case of "be disp(*,r0)" using a direct branch to disp, so that we can goto_tb to the TB containing the syscall. */ if (b == 0) { return do_dbranch(ctx, disp, is_l ? 31 : 0, n); - } else { - TCGv_reg tmp = get_temp(ctx); - tcg_gen_addi_reg(tmp, load_gpr(ctx, b), disp); - return do_ibranch(ctx, tmp, is_l ? 31 : 0, n); } +#endif + + tmp = get_temp(ctx); + tcg_gen_addi_reg(tmp, load_gpr(ctx, b), disp); + tmp = do_ibranch_priv(ctx, tmp); + return do_ibranch(ctx, tmp, is_l ? 31 : 0, n); } static DisasJumpType trans_bl(DisasContext *ctx, uint32_t insn, @@ -3490,6 +3528,7 @@ static DisasJumpType trans_blr(DisasContext *ctx, uint32_t insn, tcg_gen_shli_reg(tmp, load_gpr(ctx, rx), 3); tcg_gen_addi_reg(tmp, tmp, ctx->iaoq_f + 8); + /* The computation here never changes privilege level. */ return do_ibranch(ctx, tmp, link, n); } @@ -3508,6 +3547,7 @@ static DisasJumpType trans_bv(DisasContext *ctx, uint32_t insn, tcg_gen_shli_reg(dest, load_gpr(ctx, rx), 3); tcg_gen_add_reg(dest, dest, load_gpr(ctx, rb)); } + dest = do_ibranch_priv(ctx, dest); return do_ibranch(ctx, dest, 0, n); } @@ -3517,8 +3557,10 @@ static DisasJumpType trans_bve(DisasContext *ctx, uint32_t insn, unsigned n = extract32(insn, 1, 1); unsigned rb = extract32(insn, 21, 5); unsigned link = extract32(insn, 13, 1) ? 2 : 0; + TCGv_reg dest; - return do_ibranch(ctx, load_gpr(ctx, rb), link, n); + dest = do_ibranch_priv(ctx, load_gpr(ctx, rb)); + return do_ibranch(ctx, dest, link, n); } static const DisasInsn table_branch[] = {