From patchwork Wed Aug 16 14:25:13 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Richard Henderson X-Patchwork-Id: 714026 Delivered-To: patch@linaro.org Received: by 2002:a5d:4012:0:b0:317:ecd7:513f with SMTP id n18csp2373940wrp; Wed, 16 Aug 2023 07:29:38 -0700 (PDT) X-Google-Smtp-Source: AGHT+IF8XN44qNibrkpWnoDZRo4C+o5lNMzAFbA8P2ibMFKzz691JMKZIqMonULt6IOkkt8jF+am X-Received: by 2002:a05:620a:28d4:b0:76c:ecef:28c with SMTP id l20-20020a05620a28d400b0076cecef028cmr3151824qkp.57.1692196178097; Wed, 16 Aug 2023 07:29:38 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1692196178; cv=none; d=google.com; s=arc-20160816; b=RVPJJ/ZQQII1EHzwN3awRLhwiTR6minNxO9696lZmmJ3zajt+EyQJ2wfZmIj1jHFkX MWSjKp+vG3acfNweUO76QHPqiz8PFmOpu/HcLVk3NS0WxxbQTgbHb4CwjxwvuHXTgr7I YMpryhCoMx9RgyUzHLYb88SvM+vKnrlyTdBPVr2jrDWd0iJJy88yK+fjxor38vbq2lTE F1IyWM0BjTNUraITfI+VK+sZ9yexjtuB3gfq1jjtr2mhpHdhYSxSRaiXiiKDtulL6kkA OGqKrauDT4f0/GxeK6ZeZUGO0AbKKg7aMXUSjDmHdmworFN6l8K5oiLN5rEXeZ9KQqY0 2PYA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=sender:errors-to:list-subscribe:list-help:list-post:list-archive :list-unsubscribe:list-id:precedence:content-transfer-encoding :mime-version:references:in-reply-to:message-id:date:subject:cc:to :from:dkim-signature; bh=ytPLWEpmbfdK58FGAwysOP9qejUkqmu+jjj36juN9v8=; fh=MjZ0MyDeSGAFTsF+giMF46Ww3kUdzgx7P9v6DEIERu0=; b=vhIIg6gTnWYgxL7MPrWXiJD6jkoZvnBAWPB93gx2bU9EyztV41+nQFAj5eIw7rJhhr snDgIlbbHt1I4FupVrn5fT53u0j05i6o95X/V/UNLlnkUeXRQYozBrQ2634ny9MsltLK gPiSR/fVlBdy1pApQSKuswN+BF73y8++vqeUsGgMMGVjYUo2xy5NhdhuMJRmuPMA8pqC dOhbuEW/OvSIPpsJ5/EIUDgsmZLT2tfja1oDmZs6Kg4IO4Ews0ORRXzTqM9QjRVXpUbp XXVFsZK6nQmceQnY0UImRXIvjjLBABFH/Ygr8EbnhnYfHtTEuuz3GHw5cw1aYqo9Bi0v 2VpQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=BH3FtdE8; 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=pass (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 j22-20020a05620a289600b00768300ff9d1si8686337qkp.530.2023.08.16.07.29.37 for (version=TLS1_2 cipher=ECDHE-ECDSA-CHACHA20-POLY1305 bits=256/256); Wed, 16 Aug 2023 07:29:38 -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=pass header.i=@linaro.org header.s=google header.b=BH3FtdE8; 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=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1qWHSd-0003uf-TG; Wed, 16 Aug 2023 10:25:23 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1qWHSc-0003sV-Hu for qemu-devel@nongnu.org; Wed, 16 Aug 2023 10:25:22 -0400 Received: from mail-pf1-x42e.google.com ([2607:f8b0:4864:20::42e]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1qWHSZ-0003jc-V6 for qemu-devel@nongnu.org; Wed, 16 Aug 2023 10:25:22 -0400 Received: by mail-pf1-x42e.google.com with SMTP id d2e1a72fcca58-68706b39c4cso4794133b3a.2 for ; Wed, 16 Aug 2023 07:25:19 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1692195918; x=1692800718; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=ytPLWEpmbfdK58FGAwysOP9qejUkqmu+jjj36juN9v8=; b=BH3FtdE8f5yH/vbwS7D2X04U5PPeUc8NUpTE2Ac8XKPCNc5cdjtw7rsrTDUTaErLmK XT7ZE3+gnsFTJUTbtmMTLgT8+x6e8Wwh8tsAhZHS+/8ZUx2T0++lItaSVzZbYeYU1XD0 JCpRT2Cwih5lHz55Lm5TYegDDjJzX1cdv8udlcw60wJQ/EezFj91Vc+qs5YxRoy2U1BK 6jHtUoOmvACZ63PNhvyCK20ABdxUwNxEl1D0s3vvKyntPU7AD4m1DMbigVyzolUCXFU4 r+c9gKfJSx/4MRe4DmfYsBZ+LRxw/QL0rz9cDxpm5/F5Nyu701UAhC1z4VdpZJ+llT8G Y9hA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1692195918; x=1692800718; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=ytPLWEpmbfdK58FGAwysOP9qejUkqmu+jjj36juN9v8=; b=eZBpGEl5ApHA31hfz3HU7I1d80wC1t2R3+fy60ZJzHBJkNS1QMVUQoXUZEptksLNa9 tDxi63lnCZ7hv+EEpMIWERdy/+mlEtKln6AMTaU7dHnQdAbtNaDVRaNKHaFxXcSqCde6 ypdev+evzf8vJpON47fKnJd6yZUu1PFfK69fW6TbeJCcGxDvATD966zMjjaxFpwCNAqL ZG6+SL2G6LtbAWxhXHWRz00UxuNVHgt/sFTADuAMQXcyaBuDf2IV82z2O6nZNJLqroA6 Zvm9WZHueEKTAfKK5eAd75XTU9NspEVHFUJlbWoIxVfT/lTTecop3i+5zVmy6Tq3itA5 RVZA== X-Gm-Message-State: AOJu0YwCWP5Bnch3k/SMA+ymv+ZMkJb/u7MXCrGCbsEG9KZ32UEbQAUl Q5jedSupfSOf5tQLXUXfe254D7AFRyWXYl6XJxw= X-Received: by 2002:a05:6a20:729d:b0:129:c38e:cdd7 with SMTP id o29-20020a056a20729d00b00129c38ecdd7mr2583715pzk.38.1692195918645; Wed, 16 Aug 2023 07:25:18 -0700 (PDT) Received: from stoup.. ([2602:47:d483:7301:a064:e3f9:a812:973b]) by smtp.gmail.com with ESMTPSA id i12-20020aa78b4c000000b00678cb337353sm11156019pfd.208.2023.08.16.07.25.17 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 16 Aug 2023 07:25:18 -0700 (PDT) From: Richard Henderson To: qemu-devel@nongnu.org Cc: qemu-arm@nongnu.org, Jordan Niethe Subject: [PATCH 1/4] tcg: Add tcg_out_tb_start backend hook Date: Wed, 16 Aug 2023 07:25:13 -0700 Message-Id: <20230816142516.469743-2-richard.henderson@linaro.org> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20230816142516.469743-1-richard.henderson@linaro.org> References: <20230816142516.469743-1-richard.henderson@linaro.org> MIME-Version: 1.0 Received-SPF: pass client-ip=2607:f8b0:4864:20::42e; envelope-from=richard.henderson@linaro.org; helo=mail-pf1-x42e.google.com X-Spam_score_int: -20 X-Spam_score: -2.1 X-Spam_bar: -- X-Spam_report: (-2.1 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+patch=linaro.org@nongnu.org Sender: qemu-devel-bounces+patch=linaro.org@nongnu.org This hook may emit code at the beginning of the TB. Suggested-by: Jordan Niethe Signed-off-by: Richard Henderson Reviewed-by: Philippe Mathieu-Daudé --- tcg/tcg.c | 3 +++ tcg/aarch64/tcg-target.c.inc | 5 +++++ tcg/arm/tcg-target.c.inc | 5 +++++ tcg/i386/tcg-target.c.inc | 5 +++++ tcg/loongarch64/tcg-target.c.inc | 5 +++++ tcg/mips/tcg-target.c.inc | 5 +++++ tcg/ppc/tcg-target.c.inc | 5 +++++ tcg/riscv/tcg-target.c.inc | 5 +++++ tcg/s390x/tcg-target.c.inc | 5 +++++ tcg/sparc64/tcg-target.c.inc | 5 +++++ tcg/tci/tcg-target.c.inc | 5 +++++ 11 files changed, 53 insertions(+) diff --git a/tcg/tcg.c b/tcg/tcg.c index ddfe9a96cb..1e9b7433bb 100644 --- a/tcg/tcg.c +++ b/tcg/tcg.c @@ -108,6 +108,7 @@ static void tcg_register_jit_int(const void *buf, size_t size, __attribute__((unused)); /* Forward declarations for functions declared and used in tcg-target.c.inc. */ +static void tcg_out_tb_start(TCGContext *s); static void tcg_out_ld(TCGContext *s, TCGType type, TCGReg ret, TCGReg arg1, intptr_t arg2); static bool tcg_out_mov(TCGContext *s, TCGType type, TCGReg ret, TCGReg arg); @@ -6009,6 +6010,8 @@ int tcg_gen_code(TCGContext *s, TranslationBlock *tb, uint64_t pc_start) s->gen_insn_data = tcg_malloc(sizeof(uint64_t) * s->gen_tb->icount * start_words); + tcg_out_tb_start(s); + num_insns = -1; QTAILQ_FOREACH(op, &s->ops, link) { TCGOpcode opc = op->opc; diff --git a/tcg/aarch64/tcg-target.c.inc b/tcg/aarch64/tcg-target.c.inc index 35ca80cd56..8d71ac68f6 100644 --- a/tcg/aarch64/tcg-target.c.inc +++ b/tcg/aarch64/tcg-target.c.inc @@ -3123,6 +3123,11 @@ static void tcg_target_qemu_prologue(TCGContext *s) tcg_out_insn(s, 3207, RET, TCG_REG_LR); } +static void tcg_out_tb_start(TCGContext *s) +{ + /* nothing to do */ +} + static void tcg_out_nop_fill(tcg_insn_unit *p, int count) { int i; diff --git a/tcg/arm/tcg-target.c.inc b/tcg/arm/tcg-target.c.inc index 83e286088f..7473b23672 100644 --- a/tcg/arm/tcg-target.c.inc +++ b/tcg/arm/tcg-target.c.inc @@ -2951,6 +2951,11 @@ static void tcg_out_epilogue(TCGContext *s) (1 << TCG_REG_R10) | (1 << TCG_REG_R11) | (1 << TCG_REG_PC)); } +static void tcg_out_tb_start(TCGContext *s) +{ + /* nothing to do */ +} + typedef struct { DebugFrameHeader h; uint8_t fde_def_cfa[4]; diff --git a/tcg/i386/tcg-target.c.inc b/tcg/i386/tcg-target.c.inc index a6b2eae995..05581dd89d 100644 --- a/tcg/i386/tcg-target.c.inc +++ b/tcg/i386/tcg-target.c.inc @@ -4114,6 +4114,11 @@ static void tcg_target_qemu_prologue(TCGContext *s) tcg_out_opc(s, OPC_RET, 0, 0, 0); } +static void tcg_out_tb_start(TCGContext *s) +{ + /* nothing to do */ +} + static void tcg_out_nop_fill(tcg_insn_unit *p, int count) { memset(p, 0x90, count); diff --git a/tcg/loongarch64/tcg-target.c.inc b/tcg/loongarch64/tcg-target.c.inc index baf5fc3819..29281e954b 100644 --- a/tcg/loongarch64/tcg-target.c.inc +++ b/tcg/loongarch64/tcg-target.c.inc @@ -1698,6 +1698,11 @@ static void tcg_target_qemu_prologue(TCGContext *s) tcg_out_opc_jirl(s, TCG_REG_ZERO, TCG_REG_RA, 0); } +static void tcg_out_tb_start(TCGContext *s) +{ + /* nothing to do */ +} + static void tcg_target_init(TCGContext *s) { unsigned long hwcap = qemu_getauxval(AT_HWCAP); diff --git a/tcg/mips/tcg-target.c.inc b/tcg/mips/tcg-target.c.inc index 9faa8bdf0b..b4da737dbb 100644 --- a/tcg/mips/tcg-target.c.inc +++ b/tcg/mips/tcg-target.c.inc @@ -2628,6 +2628,11 @@ static void tcg_target_qemu_prologue(TCGContext *s) tcg_out_opc_reg(s, OPC_OR, TCG_TMP3, TCG_TMP3, TCG_TMP1); } +static void tcg_out_tb_start(TCGContext *s) +{ + /* nothing to do */ +} + static void tcg_target_init(TCGContext *s) { tcg_target_detect_isa(); diff --git a/tcg/ppc/tcg-target.c.inc b/tcg/ppc/tcg-target.c.inc index 511e14b180..a3255851fe 100644 --- a/tcg/ppc/tcg-target.c.inc +++ b/tcg/ppc/tcg-target.c.inc @@ -2482,6 +2482,11 @@ static void tcg_target_qemu_prologue(TCGContext *s) tcg_out32(s, BCLR | BO_ALWAYS); } +static void tcg_out_tb_start(TCGContext *s) +{ + /* nothing to do */ +} + static void tcg_out_exit_tb(TCGContext *s, uintptr_t arg) { tcg_out_movi(s, TCG_TYPE_PTR, TCG_REG_R3, arg); diff --git a/tcg/riscv/tcg-target.c.inc b/tcg/riscv/tcg-target.c.inc index eeaeb6b6e3..22834d087b 100644 --- a/tcg/riscv/tcg-target.c.inc +++ b/tcg/riscv/tcg-target.c.inc @@ -2054,6 +2054,11 @@ static void tcg_target_qemu_prologue(TCGContext *s) tcg_out_opc_imm(s, OPC_JALR, TCG_REG_ZERO, TCG_REG_RA, 0); } +static void tcg_out_tb_start(TCGContext *s) +{ + /* nothing to do */ +} + static volatile sig_atomic_t got_sigill; static void sigill_handler(int signo, siginfo_t *si, void *data) diff --git a/tcg/s390x/tcg-target.c.inc b/tcg/s390x/tcg-target.c.inc index a94f7908d6..379aaef1e5 100644 --- a/tcg/s390x/tcg-target.c.inc +++ b/tcg/s390x/tcg-target.c.inc @@ -3457,6 +3457,11 @@ static void tcg_target_qemu_prologue(TCGContext *s) tcg_out_insn(s, RR, BCR, S390_CC_ALWAYS, TCG_REG_R14); } +static void tcg_out_tb_start(TCGContext *s) +{ + /* nothing to do */ +} + static void tcg_out_nop_fill(tcg_insn_unit *p, int count) { memset(p, 0x07, count * sizeof(tcg_insn_unit)); diff --git a/tcg/sparc64/tcg-target.c.inc b/tcg/sparc64/tcg-target.c.inc index ffcb879211..6458ca202d 100644 --- a/tcg/sparc64/tcg-target.c.inc +++ b/tcg/sparc64/tcg-target.c.inc @@ -955,6 +955,11 @@ static void tcg_target_qemu_prologue(TCGContext *s) tcg_out_movi_s13(s, TCG_REG_O0, 0); } +static void tcg_out_tb_start(TCGContext *s) +{ + /* nothing to do */ +} + static void tcg_out_nop_fill(tcg_insn_unit *p, int count) { int i; diff --git a/tcg/tci/tcg-target.c.inc b/tcg/tci/tcg-target.c.inc index 253f27f174..95b3352f82 100644 --- a/tcg/tci/tcg-target.c.inc +++ b/tcg/tci/tcg-target.c.inc @@ -955,6 +955,11 @@ static inline void tcg_target_qemu_prologue(TCGContext *s) { } +static void tcg_out_tb_start(TCGContext *s) +{ + /* nothing to do */ +} + bool tcg_target_has_memory_bswap(MemOp memop) { return true; From patchwork Wed Aug 16 14:25:14 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Richard Henderson X-Patchwork-Id: 714028 Delivered-To: patch@linaro.org Received: by 2002:a5d:4012:0:b0:317:ecd7:513f with SMTP id n18csp2374000wrp; Wed, 16 Aug 2023 07:29:43 -0700 (PDT) X-Google-Smtp-Source: AGHT+IExaeB57mIe0+fisfDVzN7Cd/gulj+TFNHH2GeZkLEXh+fHPttHJdncVVLxysmD9ecc7GIt X-Received: by 2002:a05:6358:880b:b0:133:9da:8d9f with SMTP id hv11-20020a056358880b00b0013309da8d9fmr2479336rwb.14.1692196183145; Wed, 16 Aug 2023 07:29:43 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1692196183; cv=none; d=google.com; s=arc-20160816; b=vsyx10wCOZI+YmROA4TqIAfXb53Ot05pjRqRF3ngE58eAqyvdqQMAwly+v1bvaEjl6 1PuHCbw9KkCiyNNtWu06K8wDvWnFz/yfqszjKVIAbTaAI3LIk60F3D4u2vz9XpXYkr24 W4JhDksnbJNbSUNxzXPF4YDEOngUt9NSifwTP0iKi81O/niKGhS5auAYPG4wu79RMUTr UHFnbyCPs1DOQRIsoiJB/Gy1x9qThHfO9JCQ6jGv5cQyiX/SIi4tzmVw6uBc8aJ0G1qJ mJurexlrFdQ45zFB6ESApVTLs2PWzRhzwNvMPcH12ODP6nr+5KTO++o7cCmqUw1QoTRh n9Bg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=sender:errors-to:list-subscribe:list-help:list-post:list-archive :list-unsubscribe:list-id:precedence:content-transfer-encoding :mime-version:references:in-reply-to:message-id:date:subject:cc:to :from:dkim-signature; bh=2WfUiBV4R48StsRGeWaef0j9aTh/ONctxiuXo83IRGs=; fh=oweadga+1U1BKjDqlK8hSmEWEC1EUfcsKuPkDinEDsU=; b=Ys6WGhkx4La7DGyXy4qmUAogU9S9jfj23SKStbFs68e9gdzDAXI970KBC/tnX7rUCs eSap0YHEENGSaEn+VpKEuZOKge5RAUBR5t9pxPG9L27H6HvDArW3a0on1xcubjIxdgy2 R/yXdoOdTu5HSrPQHqPjH8fUOOnide9sxkok3+Up+r+I6sZcNOaEF4ix8VColSwy531b uJBS+dDqQTyQr1uLapJKCZ/CKwR5OxmU084stV6agNhH9pfjkbLI6YOcuf5twYrOOlCo v5H3hFHBnrJRM4iiZno4lFyAwkMkNKq3LX046D7X7tYvuUC6iNmnB+4ibAomcrmRLJbw kUuA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=er27MzP+; 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=pass (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 y17-20020a05622a121100b00403a8e58423si8843397qtx.448.2023.08.16.07.29.42 for (version=TLS1_2 cipher=ECDHE-ECDSA-CHACHA20-POLY1305 bits=256/256); Wed, 16 Aug 2023 07:29:43 -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=pass header.i=@linaro.org header.s=google header.b=er27MzP+; 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=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1qWHSg-0003xp-3M; Wed, 16 Aug 2023 10:25:26 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1qWHSd-0003uu-UC for qemu-devel@nongnu.org; Wed, 16 Aug 2023 10:25:23 -0400 Received: from mail-pf1-x42f.google.com ([2607:f8b0:4864:20::42f]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1qWHSb-0003k6-Bv for qemu-devel@nongnu.org; Wed, 16 Aug 2023 10:25:23 -0400 Received: by mail-pf1-x42f.google.com with SMTP id d2e1a72fcca58-68878ca7ca0so935353b3a.0 for ; Wed, 16 Aug 2023 07:25:20 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1692195920; x=1692800720; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=2WfUiBV4R48StsRGeWaef0j9aTh/ONctxiuXo83IRGs=; b=er27MzP+gSmorkX/8Xc1MNooYKFHycdKoxgHrnnJF93qmqML5QCzqsT7SceFsZFKfS oxcQVeiCiUqX9ElvbhaZIT9ek6KorYpZR3nR6Gu0WdsSRpQY0XTIVTUfCXd/9iUYb9/w pRKqt2JiKNyE59Udx2iX4FKaBKMtbWXEazkts+pAREml7sIf7J2qGrJPnuwqzakh2KFi Kbh2doJIItF4RxAtbcjXvIplFryYOPg70l8bDpNniCmAnAWLNWzGF3LEb/PogAnSAmwG mW55LJ8kjUmthwNTXWx3O2J4tejT5lgCRV9mPvwCBRVpbMR5IhEhCMOOB2lzXEVjUX6g CO8A== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1692195920; x=1692800720; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=2WfUiBV4R48StsRGeWaef0j9aTh/ONctxiuXo83IRGs=; b=FF6b90jYbDQ+t6nNatrm6CiNyt2o57fAipkFnTgqDYjM+qwtxqBC21+hmlBASS62kz nqVbUqWW8rM7ZHtAEOtvEA8ywDxWIYYQFPUhJOFLgTIl3nZQmgSyiLEvxwgPVZW2I+Jy esmjE+4ybPZKi/fHQ/xqLHyAaHupROldWypx59xCLWAwLoFAHy64ogdKjlsUTCJmAddN egAhnuuiB3Ep3Sy1O4fqdbirHfV4JNP01H7tIOWmJjpFobk87TIEtaJAnhVVOqgvg6Mf tP96mQx+hjC5ShzeBXLu7qrcuBNHSp1ieK+OX1Xauidu9ZxOAswb6/0cFmvroNJEijlU so+w== X-Gm-Message-State: AOJu0Yz3guLqC7gIfvsEuhRpekKtuUzpmEn/IEzGXRzBbQEMrxp2Eu12 t86myg6XXfBW9YS/7+XSfzP5YMl9olquADgP4JA= X-Received: by 2002:a05:6a00:2444:b0:687:3f06:5939 with SMTP id d4-20020a056a00244400b006873f065939mr1818513pfj.32.1692195919804; Wed, 16 Aug 2023 07:25:19 -0700 (PDT) Received: from stoup.. ([2602:47:d483:7301:a064:e3f9:a812:973b]) by smtp.gmail.com with ESMTPSA id i12-20020aa78b4c000000b00678cb337353sm11156019pfd.208.2023.08.16.07.25.19 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 16 Aug 2023 07:25:19 -0700 (PDT) From: Richard Henderson To: qemu-devel@nongnu.org Cc: qemu-arm@nongnu.org Subject: [PATCH 2/4] util/cpuinfo-aarch64: Add CPUINFO_BTI Date: Wed, 16 Aug 2023 07:25:14 -0700 Message-Id: <20230816142516.469743-3-richard.henderson@linaro.org> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20230816142516.469743-1-richard.henderson@linaro.org> References: <20230816142516.469743-1-richard.henderson@linaro.org> MIME-Version: 1.0 Received-SPF: pass client-ip=2607:f8b0:4864:20::42f; envelope-from=richard.henderson@linaro.org; helo=mail-pf1-x42f.google.com X-Spam_score_int: -20 X-Spam_score: -2.1 X-Spam_bar: -- X-Spam_report: (-2.1 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=unavailable autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+patch=linaro.org@nongnu.org Sender: qemu-devel-bounces+patch=linaro.org@nongnu.org Signed-off-by: Richard Henderson Reviewed-by: Philippe Mathieu-Daudé --- host/include/aarch64/host/cpuinfo.h | 1 + util/cpuinfo-aarch64.c | 4 ++++ 2 files changed, 5 insertions(+) diff --git a/host/include/aarch64/host/cpuinfo.h b/host/include/aarch64/host/cpuinfo.h index 769626b098..a59c8418d2 100644 --- a/host/include/aarch64/host/cpuinfo.h +++ b/host/include/aarch64/host/cpuinfo.h @@ -10,6 +10,7 @@ #define CPUINFO_LSE (1u << 1) #define CPUINFO_LSE2 (1u << 2) #define CPUINFO_AES (1u << 3) +#define CPUINFO_BTI (1u << 4) /* Initialized with a constructor. */ extern unsigned cpuinfo; diff --git a/util/cpuinfo-aarch64.c b/util/cpuinfo-aarch64.c index ababc39550..97f5548a95 100644 --- a/util/cpuinfo-aarch64.c +++ b/util/cpuinfo-aarch64.c @@ -57,11 +57,15 @@ unsigned __attribute__((constructor)) cpuinfo_init(void) info |= (hwcap & HWCAP_ATOMICS ? CPUINFO_LSE : 0); info |= (hwcap & HWCAP_USCAT ? CPUINFO_LSE2 : 0); info |= (hwcap & HWCAP_AES ? CPUINFO_AES: 0); + + unsigned long hwcap2 = qemu_getauxval(AT_HWCAP2); + info |= (hwcap2 & HWCAP2_BTI ? CPUINFO_BTI : 0); #endif #ifdef CONFIG_DARWIN info |= sysctl_for_bool("hw.optional.arm.FEAT_LSE") * CPUINFO_LSE; info |= sysctl_for_bool("hw.optional.arm.FEAT_LSE2") * CPUINFO_LSE2; info |= sysctl_for_bool("hw.optional.arm.FEAT_AES") * CPUINFO_AES; + info |= sysctl_for_bool("hw.optional.arm.FEAT_BTI") * CPUINFO_BTI; #endif cpuinfo = info; From patchwork Wed Aug 16 14:25:15 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Richard Henderson X-Patchwork-Id: 714029 Delivered-To: patch@linaro.org Received: by 2002:a5d:4012:0:b0:317:ecd7:513f with SMTP id n18csp2374066wrp; Wed, 16 Aug 2023 07:29:51 -0700 (PDT) X-Google-Smtp-Source: AGHT+IGUDelwtegWoyYiRH6CqcpoaTqtvggaQql1aT8I96noonHTOAXq/4YQkA0/9xuXM0XZSJbF X-Received: by 2002:a05:620a:2683:b0:76c:8b47:f394 with SMTP id c3-20020a05620a268300b0076c8b47f394mr2534298qkp.2.1692196190601; Wed, 16 Aug 2023 07:29:50 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1692196190; cv=none; d=google.com; s=arc-20160816; b=gB7vlzyrMr+gljj/lmGZThCkOrT47b0tZMIeIxH+QzTcY2IjrFwLPnvCeUp09uogzI QjxYbVSChrlX5Xp3fDTLVUcSvYRMkwz05sIQgqHbOwMb1z+wtKUkHAv/t0pSODPysQU1 qJifgSGEjHM74kFTUe5qiSkZsOb5aM9kEIG8j3SY4RfQtPUbBhaZLtoyuYwvnOF6n/4r dGLmhe9JarDAC+EzRSQScUx8OW0K+D71sdrua6ZfBkhylSVI1ZrI/qnYESFWcHfRKmXu V8WtkX538jdb0jY1KCgiDx74nlJbhmA1QPNQOUEs2errnnPWV/CPjuSRKoE7O8jEbyoP NYEQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=sender:errors-to:list-subscribe:list-help:list-post:list-archive :list-unsubscribe:list-id:precedence:content-transfer-encoding :mime-version:references:in-reply-to:message-id:date:subject:cc:to :from:dkim-signature; bh=72KfGjWBTb1YdYpl3rRLl1lNIdpPvxIAybrfsJIzoH4=; fh=oweadga+1U1BKjDqlK8hSmEWEC1EUfcsKuPkDinEDsU=; b=olLej8XpVLf4CPehEUZ48nkRujJEmh75iMfKv01edE8cR9hb6J6BvRkTQ8nXaYq8cz +vJq+r5QX0qiMMkaKIemPCMwv5C9kuo+UB9dTA0miqR3saXyzlTNF8gTW3V7xR6pr9jb IWKCI/7SUFB3BlFUHG7cgGMgobpCDBbk+gD0clfT10/G+nAiyM275lCUmS7+L6q8Fmr8 SSGY2s1fsZVePapD9CgH67G2p5LZuEx3Vcp8AKlDtdfglP//fTM7tGmIiIkm5Q8FExRk 7hgi+hxnz8JDkrzmeXnDTQc8BxO69JQ+AwV5UxbraswpujDp8y4YATqwoRJ5MaRT6qZK 5a8A== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=CGI7VANI; 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=pass (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 s12-20020a05620a080c00b0076cc4d494c2si8481678qks.88.2023.08.16.07.29.50 for (version=TLS1_2 cipher=ECDHE-ECDSA-CHACHA20-POLY1305 bits=256/256); Wed, 16 Aug 2023 07:29:50 -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=pass header.i=@linaro.org header.s=google header.b=CGI7VANI; 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=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1qWHSg-0003yC-CF; Wed, 16 Aug 2023 10:25:26 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1qWHSe-0003vn-IW for qemu-devel@nongnu.org; Wed, 16 Aug 2023 10:25:24 -0400 Received: from mail-pf1-x42e.google.com ([2607:f8b0:4864:20::42e]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1qWHSb-0003kH-TR for qemu-devel@nongnu.org; Wed, 16 Aug 2023 10:25:24 -0400 Received: by mail-pf1-x42e.google.com with SMTP id d2e1a72fcca58-686bc261111so4660065b3a.3 for ; Wed, 16 Aug 2023 07:25:21 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1692195921; x=1692800721; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=72KfGjWBTb1YdYpl3rRLl1lNIdpPvxIAybrfsJIzoH4=; b=CGI7VANIT8WO7Jmcpk+SUz+0TfSaYiCcxGNxg/UfK+xdVTDI0elHiAHEMboWC98lKq grGYPoX0LZsK0DG0GgvQFoUnIMAf5pr3Doqgh1J5VhsOXar7U0xb1ru1WM620X2Lqn/E zMo0qlkhNN+KC9zLbiaU5fc0t+DI9Es+44Mh2uCmReJ+8wClQeO41yNDnUtXiJXgCveW GBT5q2/zZrwvbPNZ9JQKbHMXfJdYLTQ4WbKaJm3AVjTSWH6MA7ijNJzXs9z1koEDZY6P IOkJbIIepXG//v4DBF3+BS5oZH2zthZ9DQfA6hDvj9XIuZKvFoKYtMG+XnyVxQiSKQxS Csrw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1692195921; x=1692800721; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=72KfGjWBTb1YdYpl3rRLl1lNIdpPvxIAybrfsJIzoH4=; b=hgppOb3GUSfZ8s4EzPLmyludxxfrcedwSMRs0yNn+4MNsK+HKXRV7pQK+WpOrd+ueI R0cKZafF7gDXVh2olkQNQ2U24E0HL3fcQFpq3MI/U0OnhK+JJt7W2LFbCM5HTXcqGYUw 31ZG+5JY2dBuJiBn4nGjXjUoiRRKRBhTUAfvLarLSfFkEhy6mKc1BqHarImwg6FH0S4p tbmnnrQSFqvujfS7eKQoRCY8F/SSbPuNyks5JMasMawPfr+DTpp80nAIGcjyNKmUP6UL t1hPJIFZu+UnaMPfLb9GofXrK570GEwybN6i9ekv4VvmOGtbfMGF8wce4YhYlcWpdAVR Zv8Q== X-Gm-Message-State: AOJu0Yz96+Hmf+PytGybc40nbczhneJ4RFyhmcqg6r4rxvr5ib0VRwgm 13JkQJCiHPxLCjXq2/wFDuXgxUykqP6sqVjarZ4= X-Received: by 2002:a05:6a00:22cb:b0:688:4909:d79d with SMTP id f11-20020a056a0022cb00b006884909d79dmr2086405pfj.25.1692195920693; Wed, 16 Aug 2023 07:25:20 -0700 (PDT) Received: from stoup.. ([2602:47:d483:7301:a064:e3f9:a812:973b]) by smtp.gmail.com with ESMTPSA id i12-20020aa78b4c000000b00678cb337353sm11156019pfd.208.2023.08.16.07.25.19 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 16 Aug 2023 07:25:20 -0700 (PDT) From: Richard Henderson To: qemu-devel@nongnu.org Cc: qemu-arm@nongnu.org Subject: [PATCH 3/4] tcg/aarch64: Emit BTI insns at jump landing pads Date: Wed, 16 Aug 2023 07:25:15 -0700 Message-Id: <20230816142516.469743-4-richard.henderson@linaro.org> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20230816142516.469743-1-richard.henderson@linaro.org> References: <20230816142516.469743-1-richard.henderson@linaro.org> MIME-Version: 1.0 Received-SPF: pass client-ip=2607:f8b0:4864:20::42e; envelope-from=richard.henderson@linaro.org; helo=mail-pf1-x42e.google.com X-Spam_score_int: -20 X-Spam_score: -2.1 X-Spam_bar: -- X-Spam_report: (-2.1 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+patch=linaro.org@nongnu.org Sender: qemu-devel-bounces+patch=linaro.org@nongnu.org The prologue is entered via "call"; the epilogue, each tb, and each goto_tb continuation point are all reached via "jump". As tcg_out_goto_long is only used by tcg_out_exit_tb, merge the two functions. Change the indirect register used to TCG_REG_TMP1, aka X16, so that the BTI condition created is "jump" instead of "jump or call". Signed-off-by: Richard Henderson Reviewed-by: Peter Maydell --- tcg/aarch64/tcg-target.c.inc | 49 +++++++++++++++++++++++++----------- 1 file changed, 34 insertions(+), 15 deletions(-) diff --git a/tcg/aarch64/tcg-target.c.inc b/tcg/aarch64/tcg-target.c.inc index 8d71ac68f6..fca5baea57 100644 --- a/tcg/aarch64/tcg-target.c.inc +++ b/tcg/aarch64/tcg-target.c.inc @@ -602,6 +602,10 @@ typedef enum { DMB_ISH = 0xd50338bf, DMB_LD = 0x00000100, DMB_ST = 0x00000200, + + BTI_C = 0xd503245f, + BTI_J = 0xd503249f, + BTI_JC = 0xd50324df, } AArch64Insn; static inline uint32_t tcg_in32(TCGContext *s) @@ -843,6 +847,17 @@ static void tcg_out_insn_3313(TCGContext *s, AArch64Insn insn, | rn << 5 | (rd & 0x1f)); } +static void tcg_out_bti(TCGContext *s, AArch64Insn insn) +{ + /* + * While BTI insns are nops on hosts without FEAT_BTI, + * there is no point in emitting them in that case either. + */ + if (cpuinfo & CPUINFO_BTI) { + tcg_out32(s, insn); + } +} + /* Register to register move using ORR (shifted register with no shift). */ static void tcg_out_movr(TCGContext *s, TCGType ext, TCGReg rd, TCGReg rm) { @@ -1351,18 +1366,6 @@ static void tcg_out_goto(TCGContext *s, const tcg_insn_unit *target) tcg_out_insn(s, 3206, B, offset); } -static void tcg_out_goto_long(TCGContext *s, const tcg_insn_unit *target) -{ - ptrdiff_t offset = tcg_pcrel_diff(s, target) >> 2; - if (offset == sextract64(offset, 0, 26)) { - tcg_out_insn(s, 3206, B, offset); - } else { - /* Choose X9 as a call-clobbered non-LR temporary. */ - tcg_out_movi(s, TCG_TYPE_I64, TCG_REG_X9, (intptr_t)target); - tcg_out_insn(s, 3207, BR, TCG_REG_X9); - } -} - static void tcg_out_call_int(TCGContext *s, const tcg_insn_unit *target) { ptrdiff_t offset = tcg_pcrel_diff(s, target) >> 2; @@ -1947,12 +1950,23 @@ static const tcg_insn_unit *tb_ret_addr; static void tcg_out_exit_tb(TCGContext *s, uintptr_t a0) { + const tcg_insn_unit *target; + ptrdiff_t offset; + /* Reuse the zeroing that exists for goto_ptr. */ if (a0 == 0) { - tcg_out_goto_long(s, tcg_code_gen_epilogue); + target = tcg_code_gen_epilogue; } else { tcg_out_movi(s, TCG_TYPE_I64, TCG_REG_X0, a0); - tcg_out_goto_long(s, tb_ret_addr); + target = tb_ret_addr; + } + + offset = tcg_pcrel_diff(s, target) >> 2; + if (offset == sextract64(offset, 0, 26)) { + tcg_out_insn(s, 3206, B, offset); + } else { + tcg_out_movi(s, TCG_TYPE_I64, TCG_REG_TMP1, (intptr_t)target); + tcg_out_insn(s, 3207, BR, TCG_REG_TMP1); } } @@ -1970,6 +1984,7 @@ static void tcg_out_goto_tb(TCGContext *s, int which) tcg_out32(s, I3206_B); tcg_out_insn(s, 3207, BR, TCG_REG_TMP0); set_jmp_reset_offset(s, which); + tcg_out_bti(s, BTI_J); } void tb_target_set_jmp_target(const TranslationBlock *tb, int n, @@ -3062,6 +3077,8 @@ static void tcg_target_qemu_prologue(TCGContext *s) { TCGReg r; + tcg_out_bti(s, BTI_C); + /* Push (FP, LR) and allocate space for all saved registers. */ tcg_out_insn(s, 3314, STP, TCG_REG_FP, TCG_REG_LR, TCG_REG_SP, -PUSH_SIZE, 1, 1); @@ -3102,10 +3119,12 @@ static void tcg_target_qemu_prologue(TCGContext *s) * and fall through to the rest of the epilogue. */ tcg_code_gen_epilogue = tcg_splitwx_to_rx(s->code_ptr); + tcg_out_bti(s, BTI_J); tcg_out_movi(s, TCG_TYPE_REG, TCG_REG_X0, 0); /* TB epilogue */ tb_ret_addr = tcg_splitwx_to_rx(s->code_ptr); + tcg_out_bti(s, BTI_J); /* Remove TCG locals stack space. */ tcg_out_insn(s, 3401, ADDI, TCG_TYPE_I64, TCG_REG_SP, TCG_REG_SP, @@ -3125,7 +3144,7 @@ static void tcg_target_qemu_prologue(TCGContext *s) static void tcg_out_tb_start(TCGContext *s) { - /* nothing to do */ + tcg_out_bti(s, BTI_J); } static void tcg_out_nop_fill(tcg_insn_unit *p, int count) From patchwork Wed Aug 16 14:25:16 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Richard Henderson X-Patchwork-Id: 714025 Delivered-To: patch@linaro.org Received: by 2002:a5d:4012:0:b0:317:ecd7:513f with SMTP id n18csp2373163wrp; Wed, 16 Aug 2023 07:28:01 -0700 (PDT) X-Google-Smtp-Source: AGHT+IGK1IhwRh123wqk2d2eBTtYnBqtAGIF1D74Nnxe8g8IuUMcWzzAMZSyhn8s9gY5Li7XU5L+ X-Received: by 2002:a05:620a:4143:b0:766:fbd9:2b5e with SMTP id k3-20020a05620a414300b00766fbd92b5emr2522930qko.36.1692196081329; Wed, 16 Aug 2023 07:28:01 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1692196081; cv=none; d=google.com; s=arc-20160816; b=JY1JoeiuTdKeHW4sXURZUFzo3w4ROo8kqlcop04a5jrPzfCXWYN2i9H6vuB5L+JHR1 jpeoycwpbdLWeiNTdULzoEc3f+fB6tDysGbNg13H53hGCIDUAgdN9s2nh5hgR/4yK6XD 88QWv2Kcr4RcbDY81QMfa0FPr2W5bvETu7GhJmNpgufy9kJtgjaGqxobBmDTqXiJhET/ 9SYT0IUzga3e00Zt8ViOY1bXv77kHk1iStT7gX3uPCX4kBn2URGtLwEdFPH5jiRQZJei SFvB7CDKUzdUHJCfOtKDBKGIWURg778DX9unFWaEmLN0SftZkmUq0p36C5c1D6556ltk JxaQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=sender:errors-to:list-subscribe:list-help:list-post:list-archive :list-unsubscribe:list-id:precedence:content-transfer-encoding :mime-version:references:in-reply-to:message-id:date:subject:cc:to :from:dkim-signature; bh=czkgg7jUOKlP3GcfTMH8TgF34amSntL+ZEW9hzFx4Wg=; fh=oweadga+1U1BKjDqlK8hSmEWEC1EUfcsKuPkDinEDsU=; b=mjpjm6/2wQB9kRy1Um6nDEAZSdcom7XS81cuu9wEAA5SDBY1d5R467/8WvpNQgSx36 tJfi+DcmmKUXLJvH0CCPqV6Ydp+g5ENuZpJ1yupXxstAG4YLpvikAib5AGOWlRuXAQsW NJ7PqdQL2OT0axWrgBJKa8hv1hm2JMPRlGdQn+8HH1evwH9qmquHDvx31rAEHXodGdc+ 4Mziq0HK0Oe6bc3Kds3dsSQanLpxep2o9D8YnEXM2mJNdx5enG9F8h8BCGDydOQg9xu3 fHt2tZcRovJ1bjtr30wcWdrq1bqSoN/j4Cnh9OgqbOOndTJSdetbzZsF28qxkjJiWCWj V7Pw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b="wx2Kn8X/"; 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=pass (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 b21-20020a05620a04f500b0076ccada993esi8761310qkh.139.2023.08.16.07.28.01 for (version=TLS1_2 cipher=ECDHE-ECDSA-CHACHA20-POLY1305 bits=256/256); Wed, 16 Aug 2023 07:28:01 -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=pass header.i=@linaro.org header.s=google header.b="wx2Kn8X/"; 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=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1qWHSi-00043O-Dr; Wed, 16 Aug 2023 10:25:28 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1qWHSf-0003xF-PZ for qemu-devel@nongnu.org; Wed, 16 Aug 2023 10:25:25 -0400 Received: from mail-pf1-x42f.google.com ([2607:f8b0:4864:20::42f]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1qWHSc-0003kh-UJ for qemu-devel@nongnu.org; Wed, 16 Aug 2023 10:25:25 -0400 Received: by mail-pf1-x42f.google.com with SMTP id d2e1a72fcca58-68872cadc7cso1184895b3a.1 for ; Wed, 16 Aug 2023 07:25:22 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1692195921; x=1692800721; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=czkgg7jUOKlP3GcfTMH8TgF34amSntL+ZEW9hzFx4Wg=; b=wx2Kn8X/CNoONFLsVHsBCvWiYH6pu3btMmFj4IgvAWspAno/AjBsrtfUXGBx/qKzeN yklevRitt+lOUZ2DwcYWMciAtC4ja561z5Ma2nD3YUu/cx3tItR9xiP83P+BAkHUvi8s JjQJDouc9keZQkwWqcpqlbncueY50ENsx1ZSbrFOhk8eZnx9VWbKlQKX3T/wVrkWlopG AYt/3+megQ3hXmDXGwOPqE5Q08ZG3pUiIT2u+6x/UvtMk47wcTYLa9xkZEftFcsnaUy9 PGNMIsx6KGtCh9fuH88zgGhvltvCGf09WXRypb2WoqUBcdcPGNzgM/A3WWUaeWC3+ED4 FdSA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1692195921; x=1692800721; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=czkgg7jUOKlP3GcfTMH8TgF34amSntL+ZEW9hzFx4Wg=; b=fAprKVsXpFPbxspkUVPLUSZqWM7xQc2thl2QsF+iCHvdgtMTmGF2I3cbmLFuPGqXdV 2thklWDemeWrudG4vz/MnHY18qgCoyyJIpzfga2SMAYYhs9jyn6mkWi8bDVb/UfSWNDk bsPxonA542xOheDILPlP5gwdegHuZbljlI2F+MtvkygbSFrJiPYZmCheUoxU9f78qk01 5oTFnhCv0dbZKSWnTlWVMN+Rl0qUizgVI91upEo2Fwz/muqIGCt2fmxvda3NS7Tqy8yf ZU95Y+2vRav/iNx7AkKzGoejPHTTwtyhcx6pmg6QWoJ4mkFXLHvwhpxh2g+YAls79zKw fa+w== X-Gm-Message-State: AOJu0YyyM/Xj/XyHyw/ab8EbV85XgBXFcW0eVPDRGHrophi60cJjkJX1 CMoBsipyNkPUUcjcPv1VDGyw+rCg/UzGJzCS2p8= X-Received: by 2002:a05:6a00:a93:b0:687:570:5021 with SMTP id b19-20020a056a000a9300b0068705705021mr2423164pfl.15.1692195921594; Wed, 16 Aug 2023 07:25:21 -0700 (PDT) Received: from stoup.. ([2602:47:d483:7301:a064:e3f9:a812:973b]) by smtp.gmail.com with ESMTPSA id i12-20020aa78b4c000000b00678cb337353sm11156019pfd.208.2023.08.16.07.25.21 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 16 Aug 2023 07:25:21 -0700 (PDT) From: Richard Henderson To: qemu-devel@nongnu.org Cc: qemu-arm@nongnu.org Subject: [PATCH 4/4] tcg: Map code_gen_buffer with PROT_BTI Date: Wed, 16 Aug 2023 07:25:16 -0700 Message-Id: <20230816142516.469743-5-richard.henderson@linaro.org> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20230816142516.469743-1-richard.henderson@linaro.org> References: <20230816142516.469743-1-richard.henderson@linaro.org> MIME-Version: 1.0 Received-SPF: pass client-ip=2607:f8b0:4864:20::42f; envelope-from=richard.henderson@linaro.org; helo=mail-pf1-x42f.google.com X-Spam_score_int: -20 X-Spam_score: -2.1 X-Spam_bar: -- X-Spam_report: (-2.1 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+patch=linaro.org@nongnu.org Sender: qemu-devel-bounces+patch=linaro.org@nongnu.org For linux aarch64 host supporting BTI, map the buffer to require BTI instructions at branch landing pads. Signed-off-by: Richard Henderson Reviewed-by: Philippe Mathieu-Daudé --- tcg/region.c | 39 ++++++++++++++++++++++++++++----------- 1 file changed, 28 insertions(+), 11 deletions(-) diff --git a/tcg/region.c b/tcg/region.c index 2b28ed3556..58cb68c6c8 100644 --- a/tcg/region.c +++ b/tcg/region.c @@ -33,8 +33,19 @@ #include "tcg/tcg.h" #include "exec/translation-block.h" #include "tcg-internal.h" +#include "host/cpuinfo.h" +/* + * Local source-level compatibility with Unix. + * Used by tcg_region_init below. + */ +#if defined(_WIN32) +#define PROT_READ 1 +#define PROT_WRITE 2 +#define PROT_EXEC 4 +#endif + struct tcg_region_tree { QemuMutex lock; QTree *tree; @@ -83,6 +94,16 @@ bool in_code_gen_buffer(const void *p) return (size_t)(p - region.start_aligned) <= region.total_size; } +static int host_prot_read_exec(void) +{ +#if defined(CONFIG_LINUX) && defined(HOST_AARCH64) && defined(PROT_BTI) + if (cpuinfo & CPUINFO_BTI) { + return PROT_READ | PROT_EXEC | PROT_BTI; + } +#endif + return PROT_READ | PROT_EXEC; +} + #ifdef CONFIG_DEBUG_TCG const void *tcg_splitwx_to_rx(void *rw) { @@ -505,14 +526,6 @@ static int alloc_code_gen_buffer(size_t tb_size, int splitwx, Error **errp) return PROT_READ | PROT_WRITE; } #elif defined(_WIN32) -/* - * Local source-level compatibility with Unix. - * Used by tcg_region_init below. - */ -#define PROT_READ 1 -#define PROT_WRITE 2 -#define PROT_EXEC 4 - static int alloc_code_gen_buffer(size_t size, int splitwx, Error **errp) { void *buf; @@ -567,7 +580,7 @@ static int alloc_code_gen_buffer_splitwx_memfd(size_t size, Error **errp) goto fail; } - buf_rx = mmap(NULL, size, PROT_READ | PROT_EXEC, MAP_SHARED, fd, 0); + buf_rx = mmap(NULL, size, host_prot_read_exec(), MAP_SHARED, fd, 0); if (buf_rx == MAP_FAILED) { goto fail_rx; } @@ -642,7 +655,7 @@ static int alloc_code_gen_buffer_splitwx_vmremap(size_t size, Error **errp) return -1; } - if (mprotect((void *)buf_rx, size, PROT_READ | PROT_EXEC) != 0) { + if (mprotect((void *)buf_rx, size, host_prot_read_exec()) != 0) { error_setg_errno(errp, errno, "mprotect for jit splitwx"); munmap((void *)buf_rx, size); munmap((void *)buf_rw, size); @@ -805,7 +818,7 @@ void tcg_region_init(size_t tb_size, int splitwx, unsigned max_cpus) need_prot = PROT_READ | PROT_WRITE; #ifndef CONFIG_TCG_INTERPRETER if (tcg_splitwx_diff == 0) { - need_prot |= PROT_EXEC; + need_prot |= host_prot_read_exec(); } #endif for (size_t i = 0, n = region.n; i < n; i++) { @@ -820,7 +833,11 @@ void tcg_region_init(size_t tb_size, int splitwx, unsigned max_cpus) } else if (need_prot == (PROT_READ | PROT_WRITE)) { rc = qemu_mprotect_rw(start, end - start); } else { +#ifdef CONFIG_POSIX + rc = mprotect(start, end - start, need_prot); +#else g_assert_not_reached(); +#endif } if (rc) { error_setg_errno(&error_fatal, errno,