From patchwork Fri Dec 29 06:31:23 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Richard Henderson X-Patchwork-Id: 10136083 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork.web.codeaurora.org (Postfix) with ESMTP id 5B063600C5 for ; Fri, 29 Dec 2017 06:46:09 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 4C13B2CD55 for ; Fri, 29 Dec 2017 06:46:09 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 3EF722CDB3; Fri, 29 Dec 2017 06:46:09 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-6.8 required=2.0 tests=BAYES_00,DKIM_SIGNED, RCVD_IN_DNSWL_HI,T_DKIM_INVALID autolearn=ham version=3.3.1 Received: from lists.gnu.org (lists.gnu.org [208.118.235.17]) (using TLSv1 with cipher AES256-SHA (256/256 bits)) (No client certificate requested) by mail.wl.linuxfoundation.org (Postfix) with ESMTPS id AEC392CD55 for ; Fri, 29 Dec 2017 06:46:08 +0000 (UTC) Received: from localhost ([::1]:57011 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1eUoQh-0006ZL-SH for patchwork-qemu-devel@patchwork.kernel.org; Fri, 29 Dec 2017 01:46:07 -0500 Received: from eggs.gnu.org ([2001:4830:134:3::10]:50726) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1eUoDE-00031W-3E for qemu-devel@nongnu.org; Fri, 29 Dec 2017 01:32:13 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1eUoDD-0004gL-1n for qemu-devel@nongnu.org; Fri, 29 Dec 2017 01:32:12 -0500 Received: from mail-pl0-x244.google.com ([2607:f8b0:400e:c01::244]:36837) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1eUoDC-0004g2-Ru for qemu-devel@nongnu.org; Fri, 29 Dec 2017 01:32:10 -0500 Received: by mail-pl0-x244.google.com with SMTP id b12so22519302plm.3 for ; Thu, 28 Dec 2017 22:32:10 -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=xpwPr2R8AeA3LQsy3N3pgJFgWGewNiSzGP1V343MF+U=; b=MZV28FXJffFdGeYOOeNzyaIVHSySlrp3j/1a+XHB9t00qE1XnGwaLxmKAm41I0sdn5 o7pdxtH3O8YZRXED87bGDDxbM5uOyjcx/1ueQaIdhuk6DJvFfySijxqvRkyxDFp3qcFp zOma+2UEAdtBm37hksnPkfO4VdIpCNkt0R4KU= 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=xpwPr2R8AeA3LQsy3N3pgJFgWGewNiSzGP1V343MF+U=; b=exUsbc38GjZoad/mycXfgzvOjJche0qqnFb6AOsKWLgVJpTqbnjPiTUFtyA14HpPP3 OPy+wmwrrdGUFwDl95F5wGULgAarAkvqdmpQqBBPC9/bsVMpswIu4KXfDoDr0tTpraiv ansc3Rt/rBmpnBS6gv283xkGpyeemc+8sI0TXh88cxlklKCAZfGjz8kCJ9rEPe4Ck7VD PAM+BC02ymIMzksH9rYhcPrcMUmn4IzMpx4iVoUjnhPIL44XNitJqN6NOB9XFqqpQB/M 2I3jbjLqdPjWsDofhDtyNcspF5gk6XJHaGeRl4D5deAlEp7Pz7OiG+eqL8AQ2Mqe8wpC AT9w== X-Gm-Message-State: AKGB3mLNcMhZ3AtLzdn8uMdgxeI98OjtBg7mqL2xDNXPIXeJ/3OSCmYQ sbPVST2afkOJuq8C7tSyUATZssKILfY= X-Google-Smtp-Source: ACJfBovvp0OyQramvD/8BJnFW6Elgy64cmTJ6Ke+5XCcTWu01hBbfYruewlO+151Y3h+jm59Nsb5Gg== X-Received: by 10.159.253.75 with SMTP id b11mr34563070plx.316.1514529129523; Thu, 28 Dec 2017 22:32:09 -0800 (PST) Received: from cloudburst.twiddle.net (97-113-183-164.tukw.qwest.net. [97.113.183.164]) by smtp.gmail.com with ESMTPSA id c28sm76539063pfe.69.2017.12.28.22.32.08 (version=TLS1_2 cipher=ECDHE-RSA-CHACHA20-POLY1305 bits=256/256); Thu, 28 Dec 2017 22:32:08 -0800 (PST) From: Richard Henderson To: qemu-devel@nongnu.org Date: Thu, 28 Dec 2017 22:31:23 -0800 Message-Id: <20171229063145.29167-17-richard.henderson@linaro.org> X-Mailer: git-send-email 2.14.3 In-Reply-To: <20171229063145.29167-1-richard.henderson@linaro.org> References: <20171229063145.29167-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:c01::244 Subject: [Qemu-devel] [PATCH 16/38] 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: deller@gmx.de Errors-To: qemu-devel-bounces+patchwork-qemu-devel=patchwork.kernel.org@nongnu.org Sender: "Qemu-devel" X-Virus-Scanned: ClamAV using ClamSMTP 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(-) diff --git a/target/hppa/translate.c b/target/hppa/translate.c index 4d5974c94d..918b444895 100644 --- a/target/hppa/translate.c +++ b/target/hppa/translate.c @@ -1859,6 +1859,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 @@ -3438,6 +3472,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 @@ -3446,16 +3481,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, @@ -3487,6 +3525,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); } @@ -3505,6 +3544,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); } @@ -3514,8 +3554,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[] = {