From patchwork Tue Feb 21 02:19:48 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Richard Henderson X-Patchwork-Id: 655351 Delivered-To: patch@linaro.org Received: by 2002:adf:9bcd:0:0:0:0:0 with SMTP id e13csp1725324wrc; Mon, 20 Feb 2023 18:22:44 -0800 (PST) X-Google-Smtp-Source: AK7set9V9snWAw+YTWNwVrv5bBkht4sx/mFfoVaIsNKbOfOtATQcSiRXuWA0pQgHVcSkMBmlggfC X-Received: by 2002:ad4:5d61:0:b0:557:a5c5:7e01 with SMTP id fn1-20020ad45d61000000b00557a5c57e01mr8135441qvb.25.1676946164504; Mon, 20 Feb 2023 18:22:44 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1676946164; cv=none; d=google.com; s=arc-20160816; b=ZeGj4RnA09vQb+vrG+mkdXkSIg9as/I5YTiixlNF1OlaWzqyxj7drOmZKEygHmILrL Iu2MtqYrONXN6T9IRcAsHg79g7FRIOnkyjrNjx8WRm5EMHNFv+aFcXnqk00j/kCXiKDG XwYlpCxgOuYI7dJH99A/yWIxnBQp2lm2Mozr8frZgKfbzKQS51984bIN8ayoeDGdKymf uRmek6pWnPKfb7x0sthPAWwh6WUhAcBDtawAAXclgti9/Nrh8cy1fAy/QWF6rW3EIsIk 8I+fDVtvlmf838bNS/DEh+QaPonrLmXmVXWhcZVo8aJYWgIqhLV+jQteeWbiezzt5dBR stAQ== 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=5ppe2Qcjf7oc9HJYN5MySDHbITJCBzPtX1IDnG3TMP0=; b=pow1SG+tMLUNM7jZefc2JniFc/GQRHyMb65m8fJlFRuwBrxmg3yvZHDDbnbNn6jOH6 jstmTV4v3Rn3nTK5mAynX3Hd+DeNIEcTkIPOPSDC3GOtsy2/Kdtvo+vLCdXijMdxrOuz OnY1Us4Lk8mTcLvulZFrAdZ/+36vxKnibP/AUEP52pueW8l2XfpLrRUrkMoKgDIAz0d5 zZzbg79YQf+F5MT1VUI3+30lWxodYzYDWhjT5WnfCd6uSJkgJ1J+MNmlUYhr5Fjo20an RoFju6rs3gbJo02PfBUhrFG9n5olOUNCziRERAd2xooIHke134BBOwAEOZiFkBcUENxL s20g== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=SkOM92ii; 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 o10-20020a05620a2a0a00b0073b412c98f0si11340729qkp.756.2023.02.20.18.22.44 for (version=TLS1_2 cipher=ECDHE-ECDSA-CHACHA20-POLY1305 bits=256/256); Mon, 20 Feb 2023 18:22:44 -0800 (PST) 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=SkOM92ii; 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 1pUIGd-0001kq-6X; Mon, 20 Feb 2023 21:20:31 -0500 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 1pUIGO-0001fV-Px for qemu-devel@nongnu.org; Mon, 20 Feb 2023 21:20:18 -0500 Received: from mail-pj1-x1044.google.com ([2607:f8b0:4864:20::1044]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1pUIGM-0008GF-IF for qemu-devel@nongnu.org; Mon, 20 Feb 2023 21:20:16 -0500 Received: by mail-pj1-x1044.google.com with SMTP id v3-20020a17090a6b0300b002341a2656e5so3142200pjj.1 for ; Mon, 20 Feb 2023 18:20:12 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; 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=5ppe2Qcjf7oc9HJYN5MySDHbITJCBzPtX1IDnG3TMP0=; b=SkOM92ii9nNZjeb5wi06xOzuxQmWZPxsZLw6x0oSc9Z6aUTQtD/UsU8N3gcWnFqLVg 77gKMN5P/6UICzwqEubCjGz1l1bMtsPAOkSQje/3EPPTiWhPzIr1o0uKQsGFxAkCgDz1 qeVW2q67Cyi9d7LoZpdpFTbpE4UXu8tpDV29AVAzosa6Epy2AtjDVmif3lES7xxlsU+K U40Ft5c87Fi2Rmigc+hVeTa1QL9t7X2SrcZecTDaTPy4vKlhTGEZmynAuo7B3JMyBfCG XoMQye9fsmpbImu8ujxmSp24sTb74KYnBiAAFBPCGe90CwjLyVeaKLg9dad1LG8Q9tNf mGGQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; 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=5ppe2Qcjf7oc9HJYN5MySDHbITJCBzPtX1IDnG3TMP0=; b=gcJ9yXsuUMn/xgx/V/fVArcVQ+KemkSycQKKr2K4L1wfcZP2NRNY1FZPNxuj8JZ25C Qz/ZapfNeU6MD5WL+dX0Z1h8epQbfUxQgPsyP6YJQZgS5RrrdHbQ6cP9bAUEow0/GnLK +VN4vY/KSZTiva0lTi5mUM7deGYswi/pE0FmZu6YZjFpwiUnhBNyT92+0g5bb3ppUj4v XGiOJ7Oidl8yJTZSg0l7SJLMWB3cicB9k0dOUcGzmonOhymf00gurnjOkoXCOaay7nKn S2bJoM6uyg0LuVaFmssOv6WUpcNWr0pXA8TrCDvJiRI/B+eFiqo0mqF3MILU1p0tdnDy b6/Q== X-Gm-Message-State: AO0yUKVggKIX7m5fh/KR2zUcvgCTSSg+9UbyxMLy5tW5nqoTINvUAF0a 3i+cdMVnQH6StVja3dSBrbvu/EqPaSOTssPL8cCxhA== X-Received: by 2002:a17:903:2441:b0:19a:9610:b234 with SMTP id l1-20020a170903244100b0019a9610b234mr3893497pls.1.1676946011785; Mon, 20 Feb 2023 18:20:11 -0800 (PST) Received: from stoup.. (rrcs-173-198-77-218.west.biz.rr.com. [173.198.77.218]) by smtp.gmail.com with ESMTPSA id f3-20020a170902e98300b0019141c79b1dsm8559328plb.254.2023.02.20.18.20.10 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 20 Feb 2023 18:20:11 -0800 (PST) From: Richard Henderson To: qemu-devel@nongnu.org Cc: qemu-arm@nongnu.org, Luis Machado , Thiago Jung Bauermann Subject: [PATCH v2 11/14] target/arm: Implement gdbstub pauth extension Date: Mon, 20 Feb 2023 16:19:48 -1000 Message-Id: <20230221021951.453601-12-richard.henderson@linaro.org> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20230221021951.453601-1-richard.henderson@linaro.org> References: <20230221021951.453601-1-richard.henderson@linaro.org> MIME-Version: 1.0 Received-SPF: pass client-ip=2607:f8b0:4864:20::1044; envelope-from=richard.henderson@linaro.org; helo=mail-pj1-x1044.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 extension is primarily defined by the Linux kernel NT_ARM_PAC_MASK ptrace register set. The original gdb feature consists of two masks, data and code, which are used to mask out the authentication code within a pointer. Following discussion with Luis Machado, add two more masks in order to support pointers within the high half of the address space (i.e. TTBR1 vs TTBR0). Cc: Luis Machado Cc: Thiago Jung Bauermann Resolves: https://gitlab.com/qemu-project/qemu/-/issues/1105 Signed-off-by: Richard Henderson Reviewed-by: Peter Maydell --- configs/targets/aarch64-linux-user.mak | 2 +- configs/targets/aarch64-softmmu.mak | 2 +- configs/targets/aarch64_be-linux-user.mak | 2 +- target/arm/internals.h | 2 ++ target/arm/gdbstub.c | 5 ++++ target/arm/gdbstub64.c | 34 +++++++++++++++++++++++ gdb-xml/aarch64-pauth.xml | 15 ++++++++++ 7 files changed, 59 insertions(+), 3 deletions(-) create mode 100644 gdb-xml/aarch64-pauth.xml diff --git a/configs/targets/aarch64-linux-user.mak b/configs/targets/aarch64-linux-user.mak index db552f1839..ba8bc5fe3f 100644 --- a/configs/targets/aarch64-linux-user.mak +++ b/configs/targets/aarch64-linux-user.mak @@ -1,6 +1,6 @@ TARGET_ARCH=aarch64 TARGET_BASE_ARCH=arm -TARGET_XML_FILES= gdb-xml/aarch64-core.xml gdb-xml/aarch64-fpu.xml +TARGET_XML_FILES= gdb-xml/aarch64-core.xml gdb-xml/aarch64-fpu.xml gdb-xml/aarch64-pauth.xml TARGET_HAS_BFLT=y CONFIG_SEMIHOSTING=y CONFIG_ARM_COMPATIBLE_SEMIHOSTING=y diff --git a/configs/targets/aarch64-softmmu.mak b/configs/targets/aarch64-softmmu.mak index d489e6da83..b4338e9568 100644 --- a/configs/targets/aarch64-softmmu.mak +++ b/configs/targets/aarch64-softmmu.mak @@ -1,5 +1,5 @@ TARGET_ARCH=aarch64 TARGET_BASE_ARCH=arm TARGET_SUPPORTS_MTTCG=y -TARGET_XML_FILES= gdb-xml/aarch64-core.xml gdb-xml/aarch64-fpu.xml gdb-xml/arm-core.xml gdb-xml/arm-vfp.xml gdb-xml/arm-vfp3.xml gdb-xml/arm-vfp-sysregs.xml gdb-xml/arm-neon.xml gdb-xml/arm-m-profile.xml gdb-xml/arm-m-profile-mve.xml +TARGET_XML_FILES= gdb-xml/aarch64-core.xml gdb-xml/aarch64-fpu.xml gdb-xml/arm-core.xml gdb-xml/arm-vfp.xml gdb-xml/arm-vfp3.xml gdb-xml/arm-vfp-sysregs.xml gdb-xml/arm-neon.xml gdb-xml/arm-m-profile.xml gdb-xml/arm-m-profile-mve.xml gdb-xml/aarch64-pauth.xml TARGET_NEED_FDT=y diff --git a/configs/targets/aarch64_be-linux-user.mak b/configs/targets/aarch64_be-linux-user.mak index dc78044fb1..acb5620cdb 100644 --- a/configs/targets/aarch64_be-linux-user.mak +++ b/configs/targets/aarch64_be-linux-user.mak @@ -1,7 +1,7 @@ TARGET_ARCH=aarch64 TARGET_BASE_ARCH=arm TARGET_BIG_ENDIAN=y -TARGET_XML_FILES= gdb-xml/aarch64-core.xml gdb-xml/aarch64-fpu.xml +TARGET_XML_FILES= gdb-xml/aarch64-core.xml gdb-xml/aarch64-fpu.xml gdb-xml/aarch64-pauth.xml TARGET_HAS_BFLT=y CONFIG_SEMIHOSTING=y CONFIG_ARM_COMPATIBLE_SEMIHOSTING=y diff --git a/target/arm/internals.h b/target/arm/internals.h index 370655061e..fb88b16579 100644 --- a/target/arm/internals.h +++ b/target/arm/internals.h @@ -1331,6 +1331,8 @@ int aarch64_gdb_get_sve_reg(CPUARMState *env, GByteArray *buf, int reg); int aarch64_gdb_set_sve_reg(CPUARMState *env, uint8_t *buf, int reg); int aarch64_gdb_get_fpu_reg(CPUARMState *env, GByteArray *buf, int reg); int aarch64_gdb_set_fpu_reg(CPUARMState *env, uint8_t *buf, int reg); +int aarch64_gdb_get_pauth_reg(CPUARMState *env, GByteArray *buf, int reg); +int aarch64_gdb_set_pauth_reg(CPUARMState *env, uint8_t *buf, int reg); void arm_cpu_sve_finalize(ARMCPU *cpu, Error **errp); void arm_cpu_sme_finalize(ARMCPU *cpu, Error **errp); void arm_cpu_pauth_finalize(ARMCPU *cpu, Error **errp); diff --git a/target/arm/gdbstub.c b/target/arm/gdbstub.c index bf8aff7824..062c8d447a 100644 --- a/target/arm/gdbstub.c +++ b/target/arm/gdbstub.c @@ -355,6 +355,11 @@ void arm_cpu_register_gdb_regs_for_features(ARMCPU *cpu) aarch64_gdb_set_fpu_reg, 34, "aarch64-fpu.xml", 0); } + if (isar_feature_aa64_pauth(&cpu->isar)) { + gdb_register_coprocessor(cs, aarch64_gdb_get_pauth_reg, + aarch64_gdb_set_pauth_reg, + 4, "aarch64-pauth.xml", 0); + } #endif } else { if (arm_feature(env, ARM_FEATURE_NEON)) { diff --git a/target/arm/gdbstub64.c b/target/arm/gdbstub64.c index 3d9e9e97c8..3bee892fb7 100644 --- a/target/arm/gdbstub64.c +++ b/target/arm/gdbstub64.c @@ -210,6 +210,40 @@ int aarch64_gdb_set_sve_reg(CPUARMState *env, uint8_t *buf, int reg) return 0; } +int aarch64_gdb_get_pauth_reg(CPUARMState *env, GByteArray *buf, int reg) +{ + switch (reg) { + case 0: /* pauth_dmask */ + case 1: /* pauth_cmask */ + case 2: /* pauth_dmask_high */ + case 3: /* pauth_cmask_high */ + /* + * Note that older versions of this feature only contained + * pauth_{d,c}mask, for use with Linux user processes, and + * thus exclusively in the low half of the address space. + * + * To support system mode, and to debug kernels, two new regs + * were added to cover the high half of the address space. + * For the purpose of pauth_ptr_mask, we can use any well-formed + * address within the address space half -- here, 0 and -1. + */ + { + bool is_data = !(reg & 1); + bool is_high = reg & 2; + uint64_t mask = pauth_ptr_mask(env, -is_high, is_data); + return gdb_get_reg64(buf, mask); + } + default: + return 0; + } +} + +int aarch64_gdb_set_pauth_reg(CPUARMState *env, uint8_t *buf, int reg) +{ + /* All pseudo registers are read-only. */ + return 0; +} + static void output_vector_union_type(GString *s, int reg_width, const char *name) { diff --git a/gdb-xml/aarch64-pauth.xml b/gdb-xml/aarch64-pauth.xml new file mode 100644 index 0000000000..24af5f903c --- /dev/null +++ b/gdb-xml/aarch64-pauth.xml @@ -0,0 +1,15 @@ + + + + + + + + + + +