From nobody Mon Nov 10 01:22:22 2025 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Authentication-Results: mx.zohomail.com; spf=pass (zoho.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=fail(p=none dis=none) header.from=redhat.com Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1552481273153887.442681585375; Wed, 13 Mar 2019 05:47:53 -0700 (PDT) Received: from localhost ([127.0.0.1]:44015 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1h43IT-0006XE-5Q for importer@patchew.org; Wed, 13 Mar 2019 08:47:49 -0400 Received: from eggs.gnu.org ([209.51.188.92]:33287) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1h43Bx-0001ML-Fd for qemu-devel@nongnu.org; Wed, 13 Mar 2019 08:41:08 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1h43Bv-0005Lb-Qo for qemu-devel@nongnu.org; Wed, 13 Mar 2019 08:41:05 -0400 Received: from mx1.redhat.com ([209.132.183.28]:23378) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1h43Bs-0005Iq-R0 for qemu-devel@nongnu.org; Wed, 13 Mar 2019 08:41:02 -0400 Received: from smtp.corp.redhat.com (int-mx07.intmail.prod.int.phx2.redhat.com [10.5.11.22]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id E7EA3C066441; Wed, 13 Mar 2019 12:40:59 +0000 (UTC) Received: from donizetti.redhat.com (ovpn-112-43.ams2.redhat.com [10.36.112.43]) by smtp.corp.redhat.com (Postfix) with ESMTP id EC6601001E6F; Wed, 13 Mar 2019 12:40:57 +0000 (UTC) From: Paolo Bonzini To: qemu-devel@nongnu.org Date: Wed, 13 Mar 2019 13:40:40 +0100 Message-Id: <20190313124042.12855-6-pbonzini@redhat.com> In-Reply-To: <20190313124042.12855-1-pbonzini@redhat.com> References: <20190313124042.12855-1-pbonzini@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.84 on 10.5.11.22 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.31]); Wed, 13 Mar 2019 12:40:59 +0000 (UTC) Content-Transfer-Encoding: quoted-printable X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] X-Received-From: 209.132.183.28 Subject: [Qemu-devel] [PATCH 5/7] tcg/i386: add support for IBT 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: fweimer@redhat.com, kwolf@redhat.com, richard.henderson@linaro.org, stefanha@redhat.com Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" Content-Type: text/plain; charset="utf-8" Add endbr annotations before indirect branch targets. This lets QEMU enable IBT even for TCG-enabled builds. Signed-off-by: Paolo Bonzini Reviewed-by: Richard Henderson --- Makefile.target | 2 ++ configure | 9 +++++++++ tcg/i386/tcg-target.inc.c | 14 ++++++++++++++ 3 files changed, 25 insertions(+) diff --git a/Makefile.target b/Makefile.target index fa143d7b4b..df413c9b7f 100644 --- a/Makefile.target +++ b/Makefile.target @@ -114,8 +114,10 @@ obj-y +=3D accel/ obj-$(CONFIG_TCG) +=3D tcg/tcg.o tcg/tcg-op.o tcg/tcg-op-vec.o tcg/tcg-op-= gvec.o obj-$(CONFIG_TCG) +=3D tcg/tcg-common.o tcg/optimize.o ifeq ($(CONFIG_CET),y) +ifneq ($(CONFIG_CET_TCG),y) tcg/tcg.o-cflags :=3D -fcf-protection=3Dreturn endif +endif obj-$(CONFIG_TCG_INTERPRETER) +=3D tcg/tci.o obj-$(CONFIG_TCG_INTERPRETER) +=3D disas/tci.o obj-$(CONFIG_TCG) +=3D fpu/softfloat.o diff --git a/configure b/configure index 4470fe8e74..4e553e521b 100755 --- a/configure +++ b/configure @@ -5096,6 +5096,11 @@ if test "$cet" =3D ""; then cet=3Dyes QEMU_CFLAGS=3D"-fcf-protection $QEMU_CFLAGS" fi +if test "$cpu" =3D "x86_64"; then + cet_tcg=3Dyes +else + cet_tcg=3Dno +fi =20 ########################################## # check and set a backend for coroutine @@ -6290,6 +6295,7 @@ echo "TCG support $tcg" if test "$tcg" =3D "yes" ; then echo "TCG debug enabled $debug_tcg" echo "TCG interpreter $tcg_interpreter" + echo "TCG CET support $cet_tcg" fi echo "malloc trim support $malloc_trim" echo "RDMA support $rdma" @@ -6495,6 +6501,9 @@ fi if test "$cet" =3D "yes" ; then echo "CONFIG_CET=3Dy" >> $config_host_mak fi +if test "$cet_tcg" =3D "yes" ; then + echo "CONFIG_CET_TCG=3Dy" >> $config_host_mak +fi if test "$slirp" !=3D "no"; then echo "CONFIG_SLIRP=3Dy" >> $config_host_mak echo "CONFIG_SMBD_COMMAND=3D\"$smbd\"" >> $config_host_mak diff --git a/tcg/i386/tcg-target.inc.c b/tcg/i386/tcg-target.inc.c index 781b1faec2..4d1f80c1b2 100644 --- a/tcg/i386/tcg-target.inc.c +++ b/tcg/i386/tcg-target.inc.c @@ -808,6 +808,17 @@ static inline void tgen_arithr(TCGContext *s, int subo= p, int dest, int src) tcg_out_modrm(s, OPC_ARITH_GvEv + (subop << 3) + ext, dest, src); } =20 +static void tcg_out_endbr(TCGContext *s) +{ +#if defined __CET__ && (__CET__ & 1) +#ifdef __x86_64__ + tcg_out32(s, 0xfa1e0ff3); +#else + tcg_out32(s, 0xfb1e0ff3); +#endif +#endif +} + static void tcg_out_mov(TCGContext *s, TCGType type, TCGReg ret, TCGReg ar= g) { int rexw =3D 0; @@ -3499,6 +3510,7 @@ static const int tcg_target_callee_save_regs[] =3D { =20 static inline void tcg_out_start(TCGContext *s) { + tcg_out_endbr(s); } =20 /* Generate global QEMU prologue and epilogue code */ @@ -3514,6 +3526,7 @@ static void tcg_target_qemu_prologue(TCGContext *s) CPU_TEMP_BUF_NLONGS * sizeof(long)); =20 /* Save all callee saved registers. */ + tcg_out_endbr(s); for (i =3D 0; i < ARRAY_SIZE(tcg_target_callee_save_regs); i++) { tcg_out_push(s, tcg_target_callee_save_regs[i]); } @@ -3553,6 +3566,7 @@ static void tcg_target_qemu_prologue(TCGContext *s) * and fall through to the rest of the epilogue. */ s->code_gen_epilogue =3D s->code_ptr; + tcg_out_endbr(s); tcg_out_movi(s, TCG_TYPE_REG, TCG_REG_EAX, 0); =20 /* TB epilogue */ --=20 2.20.1