From patchwork Tue Feb 14 16:30:45 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Richard Henderson X-Patchwork-Id: 653479 Delivered-To: patch@linaro.org Received: by 2002:adf:f90f:0:0:0:0:0 with SMTP id b15csp3147680wrr; Tue, 14 Feb 2023 08:34:00 -0800 (PST) X-Google-Smtp-Source: AK7set/PqvZ/JRMe5ZNEjxn4NSEp2c5FlOlePvXo4elk7QOzh3PVogbRNmMWQOnGrjyjtGsO2viy X-Received: by 2002:a05:622a:180c:b0:3b9:c44e:361 with SMTP id t12-20020a05622a180c00b003b9c44e0361mr3911350qtc.64.1676392440768; Tue, 14 Feb 2023 08:34:00 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1676392440; cv=none; d=google.com; s=arc-20160816; b=1LAJqsBTXSnA1Nb8k9baIiF0vwtVEvCi+djuCzvcMj/0ZYnKAr7tHnCAttZdbBYfyP QuDbTw/KBSY/eTFwvg73uwlvIL9f4laTz9TiC2spv9lcVGS7K8Yh4vwzumA4+2Q/cJSX iCuJgDsAvlT3rRomxNUhYempsBas/xa77lWNUeLWa86d3E9/DXOMEuK+gT8BqtYpqeor 0iPplEDEt6ErlzOXkBVgUrr/3w6/OAL3bRfCfq0ZdzspizkfkWEehpjWfh9cIdVXN4+2 Xy/SE0eQb1y5j/91hgfIPh+4oOBe1PM2tgusvT/A1fcL8P15yQmt7+I+sy9grx11ztO5 ygKQ== 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=I2TaPq9VaeUx5FG1r+qvVw6gD0hnlJ7wu2KVNSomLWo=; b=ZdLPZwvn8zUcR4btQPPvm6Wbcpw92udkXPLT6NBmYC12dLzf/Lvck3sXt10R1j8l3k qkh8CqncBgBBup5dD9xLMdJw3T1NAajBxDhH67KW0yAgYkC0iTnQ62Y2suG9R5PIsEUF q7WZXPTjsIKbDPMOKLO49WfIRewTb+rwQv5I3i7N60d6C/GaBkMMcjggmPStLHDoKaRl e/nk+HR1GEAsK8BZXHBAnevGb+HXLlP4R8WwTdKn3qHIQ0TxQm6E29Y7nol75aFfDn59 +TxASd1HtCiaYfMaYRgcrFiYkeC1PZvUneZ5+m2ZdJ0ppJ4k4DRF7/wHZbMmeX0BYipH 1shQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=jOFtG0jQ; 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 t11-20020a05622a180b00b003b639a807b1si12946271qtc.748.2023.02.14.08.34.00 for (version=TLS1_2 cipher=ECDHE-ECDSA-CHACHA20-POLY1305 bits=256/256); Tue, 14 Feb 2023 08:34:00 -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=jOFtG0jQ; 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 1pRyD5-0006jY-Fs; Tue, 14 Feb 2023 11:31:15 -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 1pRyD2-0006a4-4T for qemu-devel@nongnu.org; Tue, 14 Feb 2023 11:31:12 -0500 Received: from mail-pf1-x444.google.com ([2607:f8b0:4864:20::444]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1pRyCz-0002Bf-OF for qemu-devel@nongnu.org; Tue, 14 Feb 2023 11:31:11 -0500 Received: by mail-pf1-x444.google.com with SMTP id s20so10546904pfe.2 for ; Tue, 14 Feb 2023 08:31:09 -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=I2TaPq9VaeUx5FG1r+qvVw6gD0hnlJ7wu2KVNSomLWo=; b=jOFtG0jQ0SzmgP/5Za2Gq4Vz1T3ikmlbo/6ypCyMxF+jiMS2go9SVKqzc6NAvRiTlB mp7mQyeQ2Jx0FxGE+TYTSlDWWemvboK+1drXO/Si+M9vXwcgIFdH+o5VY4iHiAEhpBb5 hfUo3b3GT5a8hE9FsanqFtJfOTdQRt30UyYfweFXzQDBP/hTgz83bRHCxjgG/gE+17rU QWtVwzdcpGz+Hlnp8+L334L/0Zs/Xzmxi5mbUBUzPmoODJwTsgrKsA8SM54CZsp4Q6ba T8BTzK92T0hVHD0vRQ1QM4Xkaeb6q6nTL1A/WJCIPI2G85WtYezZseQSYsXM1vkLjewX MskQ== 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=I2TaPq9VaeUx5FG1r+qvVw6gD0hnlJ7wu2KVNSomLWo=; b=LjIRmYNA3h8fUw5vqZex18wDK09Yf/xOCSJs5LXvBadoJT7RrpQFMX8YG34Dar26WX TJi/mNZ9FGTTK8h9ZbsZN+ZN//ndQQdvXY1Opo7xvdqBhM6zf4KTyKu/OLyTeQ8q1fw9 UgkQXgFUOpgvldY7yMT8Fhcb+zoDFa9n/U0RzQpEgSkuHsELJfG3KtEnV3YE3pT7tTiN d5zksK9oJa48KPNjouD+W07BOWRTT48jwKVg+V4oagHgv0jeXoZlc84e5xWFw+ebGSSo 4hG4/Itz3AUAGkGdbg5okLsnFF4zDD5RRcFl1nUqXtNFSVOyK7ASWFk7F2evpH4kY+2Q mrRw== X-Gm-Message-State: AO0yUKXY4QlbUnZ8u0eLYsVzUTN2NfSoItWhbup3F2MuWneHQSo2DzPb X+qD5DVfWrP5G7IBc5L3UxP2ekyVbFAhuQSkqvlqMA== X-Received: by 2002:aa7:9f49:0:b0:5a8:c90d:ab17 with SMTP id h9-20020aa79f49000000b005a8c90dab17mr2561378pfr.15.1676392268321; Tue, 14 Feb 2023 08:31:08 -0800 (PST) Received: from stoup.. (rrcs-74-87-59-234.west.biz.rr.com. [74.87.59.234]) by smtp.gmail.com with ESMTPSA id d17-20020aa78691000000b0058d99337381sm10337011pfo.172.2023.02.14.08.31.06 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 14 Feb 2023 08:31:07 -0800 (PST) From: Richard Henderson To: qemu-devel@nongnu.org Cc: qemu-arm@nongnu.org, Luis Machado , Thiago Jung Bauermann Subject: [PATCH 11/14] target/arm: Implement gdbstub pauth extension Date: Tue, 14 Feb 2023 06:30:45 -1000 Message-Id: <20230214163048.903964-12-richard.henderson@linaro.org> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20230214163048.903964-1-richard.henderson@linaro.org> References: <20230214163048.903964-1-richard.henderson@linaro.org> MIME-Version: 1.0 Received-SPF: pass client-ip=2607:f8b0:4864:20::444; envelope-from=richard.henderson@linaro.org; helo=mail-pf1-x444.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 --- 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 | 29 +++++++++++++++++++++++ gdb-xml/aarch64-pauth.xml | 15 ++++++++++++ 7 files changed, 54 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 bb3983645d..4b60355a7e 100644 --- a/target/arm/internals.h +++ b/target/arm/internals.h @@ -1345,6 +1345,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 a6a8e7eb40..465d7fb196 100644 --- a/target/arm/gdbstub64.c +++ b/target/arm/gdbstub64.c @@ -210,6 +210,35 @@ 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 -2. + */ + return gdb_get_reg64(buf, pauth_ptr_mask(env, -(reg & 2), ~reg & 1)); + 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 @@ + + + + + + + + + + +