From patchwork Sun Aug 25 14:52:05 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Gustavo Romero X-Patchwork-Id: 822363 Delivered-To: patch@linaro.org Received: by 2002:adf:e044:0:b0:367:895a:4699 with SMTP id w4csp1172711wrh; Sun, 25 Aug 2024 07:53:38 -0700 (PDT) X-Forwarded-Encrypted: i=2; AJvYcCVejfaXtd0nMucMh6WSFJ6ym6dgdhKGrcCjxhfar18PpK8jBR12wLkiNDodJb5FXf09XQ+GPw==@linaro.org X-Google-Smtp-Source: AGHT+IEc6+uAuw2Qoiz7cb4ZLae95RQSqxwfz+scY9I7v/OXqAlqW/3TVOF0pOh7TODN3vKxc5Jn X-Received: by 2002:a05:690c:101:b0:6b1:c05:f31 with SMTP id 00721157ae682-6c629345784mr73675007b3.36.1724597618511; Sun, 25 Aug 2024 07:53:38 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1724597618; cv=none; d=google.com; s=arc-20160816; b=b0VzNMxTnn43oxVgLIZJdIUGywWHm7rNsiZrcvmAgV/V8L+z+/J/2dFhn589qp9cMM fO8HCQIm/5A70GwnLs0iz1uxCXeadEEpBUQdO8W0ZqfWpms9yTMsrXZ7MNgnQlqcyOkc kHwO2EXmnkTLR8enXOYFjmF5AzW2IdCp17d9oB9xuUj11Uab9C8+xCC589RkY+76+rGa 4cmpoWYZBgcLmzXC9qDAPgMQi+9MyNq+8IYD1mhED6JD63Zg2gKhOALfWk+1AM0Q4Lfk TU+HEaZnA42upAl03+ofnUnZkUNBSJXtpx96ZzHLEiHfhZBH8duJISPkwQHNqsmZC+LN N2jQ== 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=jMYYkx/opjLXIlYN94qCm43SuWEXEBRd8nT29zGh3do=; fh=b5q3cJgcc12gnKfUWQQbBLXKRqia4x4Q8oLG+cCF/wU=; b=W4YJi/gI4sS8OsrEty1+EI2y0elelMbr+77tagqkLy3kw6TzjRur7f4iCsZjU+po3z DZQBPKj0P85/uyflGw+WFe9KpGoH+9uRhvYdt4jnzEZbV/AQlPyTkg3dM9ztNLUHn5Vx L18dBSddgbvCj2M7puaUxcQ1qwuCu8eZkIZa6FZ7HKTLs0JYJal9fRK4TRN8sWMM6bnv i8X3gSXw3x2cUoD8smqK0iSZppxPQav6culkGeUxBCkfPpeATmzyW97hKjtPblqFfXvb aUmOmiGyhJu4NdddBt1WE57+IoH56MImbxCBqkTg34HfhiXFH1QWaXwQhF2Gbjty41bf M3kA==; dara=google.com ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=yT6jq6EB; 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; dara=neutral header.i=@linaro.org Return-Path: Received: from lists.gnu.org (lists.gnu.org. [209.51.188.17]) by mx.google.com with ESMTPS id af79cd13be357-7a67f4297c7si887673385a.641.2024.08.25.07.53.38 for (version=TLS1_2 cipher=ECDHE-ECDSA-CHACHA20-POLY1305 bits=256/256); Sun, 25 Aug 2024 07:53: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=yT6jq6EB; 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; dara=neutral header.i=@linaro.org Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1siEbw-0002Ze-69; Sun, 25 Aug 2024 10:52:56 -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 1siEbu-0002SW-6v for qemu-devel@nongnu.org; Sun, 25 Aug 2024 10:52:54 -0400 Received: from mail-pl1-x635.google.com ([2607:f8b0:4864:20::635]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1siEbs-0005v6-Df for qemu-devel@nongnu.org; Sun, 25 Aug 2024 10:52:53 -0400 Received: by mail-pl1-x635.google.com with SMTP id d9443c01a7336-201ee6b084bso29145625ad.2 for ; Sun, 25 Aug 2024 07:52:51 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1724597570; x=1725202370; darn=nongnu.org; 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=jMYYkx/opjLXIlYN94qCm43SuWEXEBRd8nT29zGh3do=; b=yT6jq6EBoP81fVEQKEYyQ/L2yews23NiEKxJS38Cnphe6O7kJUEjO17i9dtS3I0Yka sYf4y+3o5G1HTWHlFwW09Qf3Kb1IQ7jffHXgbkw6v6qL6oe1aNzIxLu908sCoX1Pi1Y1 uHf8qY6e0tPZ/QVvZtKs2D3NVN4XorwRTajkqCwziJGZJRN4vc9bYFOlv9NmLH27dQaX OMzmP4tQfVuN2VsEFg/tpR+uP1ngLUn3wWxR3y9XiK5+Ye0NpXk786aSHJwbaacrXX/2 jCbtCBprieqX0xyXOxpkdtspTDcRMQc1SWhTudgrFEjoy9jCb39qoH8fChEL2b/j4VPS 2T2w== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1724597570; x=1725202370; 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=jMYYkx/opjLXIlYN94qCm43SuWEXEBRd8nT29zGh3do=; b=qkaAQMQB3swpvfKyCxUye9BUVcanFMnrK+BAdqC8ChYpXgyui0n5xTiRIT/wTAunaJ +bIomjwzYVysVZHk0kztcFlFjsXGCp+M5hmGMEO7jS5A7M0u4ETHrEtWWmFS5T22KAWO CO5T60PZUMTBoxT+9G/p2R/nedw8zS0ImCbJQrL7IYbVOrTYNxxWUdZBldy6gX/Yz8oJ gWQ4ytynlHiZXWisdtUrc4PgibRsVzesHUGvSMdchFM3/iBNazOFj/59S0yOhYrLWHto bg/A7YDIc7GR1k6Wxw4bXAiysHFaMzvnr5kdbJy2vs5JUq5Qd8upMa59zHx8MAK5PJi9 IBQg== X-Gm-Message-State: AOJu0Yyl3qxHTprsI5DVdLB9fiDEKMiipBCuzrMGkNLIxSbxpSb6+XIP Wpc+ZpjMdmmVgD+7cjVStckrFv3vnWZ4rYDdNDLeEuFVDtw2QRiV5kqYZLeTcmczPLwypKNEaED U6UA= X-Received: by 2002:a17:902:dac4:b0:203:a116:7953 with SMTP id d9443c01a7336-203a1167a2dmr100748205ad.10.1724597569726; Sun, 25 Aug 2024 07:52:49 -0700 (PDT) Received: from amd.. ([2804:7f0:b400:bb79:3e7c:3fff:fe7a:e83b]) by smtp.gmail.com with ESMTPSA id d9443c01a7336-203b0e164b8sm24698805ad.236.2024.08.25.07.52.47 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 25 Aug 2024 07:52:49 -0700 (PDT) From: Gustavo Romero To: qemu-devel@nongnu.org, alex.bennee@linaro.org, richard.henderson@linaro.org Cc: philmd@linaro.org, peter.maydell@linaro.org, gustavo.romero@linaro.org Subject: [PATCH v3 1/4] gdbstub: Use specific MMU index when probing MTE addresses Date: Sun, 25 Aug 2024 14:52:05 +0000 Message-Id: <20240825145208.46774-2-gustavo.romero@linaro.org> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20240825145208.46774-1-gustavo.romero@linaro.org> References: <20240825145208.46774-1-gustavo.romero@linaro.org> MIME-Version: 1.0 Received-SPF: pass client-ip=2607:f8b0:4864:20::635; envelope-from=gustavo.romero@linaro.org; helo=mail-pl1-x635.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, T_SCC_BODY_TEXT_LINE=-0.01 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 Use cpu_mmu_index() to determine the specific translation regime (MMU index) before probing addresses using allocation_tag_mem_probe(). Currently, the MMU index is hardcoded to 0 and only works for user mode. By obtaining the specific MMU index according to the translation regime, future use of the stubs relying on allocation_tag_mem_probe in other regimes will be possible, like in EL1. This commit also changes the ptr_size value passed to allocation_tag_mem_probe() from 8 to 1. The ptr_size parameter actually represents the number of bytes in the memory access (which can be as small as 1 byte), rather than the number of bits used in the address space pointed to by ptr. Signed-off-by: Gustavo Romero Reviewed-by: Richard Henderson --- target/arm/gdbstub64.c | 17 +++++++++++++---- 1 file changed, 13 insertions(+), 4 deletions(-) diff --git a/target/arm/gdbstub64.c b/target/arm/gdbstub64.c index 5221381cc8..85a19c14c7 100644 --- a/target/arm/gdbstub64.c +++ b/target/arm/gdbstub64.c @@ -435,6 +435,7 @@ static void handle_q_memtag(GArray *params, void *user_ctx) { ARMCPU *cpu = ARM_CPU(user_ctx); CPUARMState *env = &cpu->env; + uint32_t mmu_index; uint64_t addr = gdb_get_cmd_param(params, 0)->val_ull; uint64_t len = gdb_get_cmd_param(params, 1)->val_ul; @@ -458,8 +459,10 @@ static void handle_q_memtag(GArray *params, void *user_ctx) gdb_put_packet("E03"); } + /* Find out the current translation regime for probe. */ + mmu_index = cpu_mmu_index(env_cpu(env), false); /* Note that tags are packed here (2 tags packed in one byte). */ - tags = allocation_tag_mem_probe(env, 0, addr, MMU_DATA_LOAD, 8 /* 64-bit */, + tags = allocation_tag_mem_probe(env, mmu_index, addr, MMU_DATA_LOAD, 1, MMU_DATA_LOAD, true, 0); if (!tags) { /* Address is not in a tagged region. */ @@ -478,13 +481,16 @@ static void handle_q_isaddresstagged(GArray *params, void *user_ctx) { ARMCPU *cpu = ARM_CPU(user_ctx); CPUARMState *env = &cpu->env; + uint32_t mmu_index; uint64_t addr = gdb_get_cmd_param(params, 0)->val_ull; uint8_t *tags; const char *reply; - tags = allocation_tag_mem_probe(env, 0, addr, MMU_DATA_LOAD, 8 /* 64-bit */, + /* Find out the current translation regime for probe. */ + mmu_index = cpu_mmu_index(env_cpu(env), false); + tags = allocation_tag_mem_probe(env, mmu_index, addr, MMU_DATA_LOAD, 1, MMU_DATA_LOAD, true, 0); reply = tags ? "01" : "00"; @@ -495,6 +501,7 @@ static void handle_Q_memtag(GArray *params, void *user_ctx) { ARMCPU *cpu = ARM_CPU(user_ctx); CPUARMState *env = &cpu->env; + uint32_t mmu_index; uint64_t start_addr = gdb_get_cmd_param(params, 0)->val_ull; uint64_t len = gdb_get_cmd_param(params, 1)->val_ul; @@ -527,8 +534,10 @@ static void handle_Q_memtag(GArray *params, void *user_ctx) * Get all tags in the page starting from the tag of the start address. * Note that there are two tags packed into a single byte here. */ - tags = allocation_tag_mem_probe(env, 0, start_addr, MMU_DATA_STORE, - 8 /* 64-bit */, MMU_DATA_STORE, true, 0); + /* Find out the current translation regime for probe. */ + mmu_index = cpu_mmu_index(env_cpu(env), false); + tags = allocation_tag_mem_probe(env, mmu_index, start_addr, MMU_DATA_STORE, + 1, MMU_DATA_STORE, true, 0); if (!tags) { /* Address is not in a tagged region. */ gdb_put_packet("E04"); From patchwork Sun Aug 25 14:52:06 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Gustavo Romero X-Patchwork-Id: 822361 Delivered-To: patch@linaro.org Received: by 2002:adf:e044:0:b0:367:895a:4699 with SMTP id w4csp1172703wrh; Sun, 25 Aug 2024 07:53:38 -0700 (PDT) X-Forwarded-Encrypted: i=2; AJvYcCWs4KYa4Gm+iviVhBFAjohXFCDXzJtvzjWBO8e0e3WBIYjizZIbk7tAgRKb8pcN52EznnxTEQ==@linaro.org X-Google-Smtp-Source: AGHT+IH0SMxYHQI5mI2gxSrxsu6S70ciL4/1bnU9BNs/oaDkH/6YfW1/mcRCaLgMsKJBQlGAsVJf X-Received: by 2002:a05:690c:6ac8:b0:6bd:5245:5e24 with SMTP id 00721157ae682-6c625b4539bmr91270427b3.21.1724597617925; Sun, 25 Aug 2024 07:53:37 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1724597617; cv=none; d=google.com; s=arc-20160816; b=nbEecJUpEroNu2DpZqOuVzdUfG5M1/xSyWqbJGEZjISJGirqrLiXDgS8lJCiXpCsJi 7WPbU3EmFIcPPllEv5qKfd/YvsCg6QxS4DF14RVqmsqAg4FAkXJR3XN8vqcntPziu/EK YfbHD/DhlTMMuzx2I6U8N+rp/xxav4YPtH3PkweBZ/ZvRlZUUAXoZJVMysgjmQJH3z4P rMfNicAAMsCYA1ww5S+7f+uiEc8uJnvP+TAtTO+AfVWhTk7DrTGROOGcvCWWqE+vDxNb 0RJQilkif1aJwDIeLPzwN6OH0grLwnCcv39pgNcLYp3ewmdZqyMOVa4x5VcwBbAd2/+F Up6w== 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=LA4jeEZSXIyNF/wBhldtI2p7w4RNntmuoAerN03i6Nk=; fh=b5q3cJgcc12gnKfUWQQbBLXKRqia4x4Q8oLG+cCF/wU=; b=Ji7yNana0eoF9KJMGOz7b9nSK1BOIDmL0Iiwwvi/RMu4N40xNKKX4h2xHkEg76er2k u+jWdDmT6+uI5zSN/JKn6C/IW+VwRUDe4lO+2YmOG3uZ3QNtg/FBDmdSNZB7IuRRXXov kKq8CMwrU39E8fQmDeV1zIj9ferouBn/+3DuokMXsi8THlzTwIJ4AwugTEJONKRcTlqG t25yT3Zlao3O6OZqOBNwBKB+I0WMma7NLhzblZ5kZjSNYQyc1LpMjyJ/JSi3QlBsSlOo 6UxGh4yhdKpfevCTAYXgPOpuxZPCMExeC8CbfpFOuY62iIvLiznXs2pwztJi4yzkT8el ubcQ==; dara=google.com ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=toJfdckT; 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; dara=neutral header.i=@linaro.org Return-Path: Received: from lists.gnu.org (lists.gnu.org. [209.51.188.17]) by mx.google.com with ESMTPS id af79cd13be357-7a67f328da0si866877585a.27.2024.08.25.07.53.37 for (version=TLS1_2 cipher=ECDHE-ECDSA-CHACHA20-POLY1305 bits=256/256); Sun, 25 Aug 2024 07:53:37 -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=toJfdckT; 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; dara=neutral header.i=@linaro.org Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1siEbx-0002gY-Tg; Sun, 25 Aug 2024 10:52:57 -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 1siEbv-0002Z4-V2 for qemu-devel@nongnu.org; Sun, 25 Aug 2024 10:52:56 -0400 Received: from mail-pg1-x530.google.com ([2607:f8b0:4864:20::530]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1siEbu-0005vM-C8 for qemu-devel@nongnu.org; Sun, 25 Aug 2024 10:52:55 -0400 Received: by mail-pg1-x530.google.com with SMTP id 41be03b00d2f7-6e7b121be30so2212597a12.1 for ; Sun, 25 Aug 2024 07:52:53 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1724597572; x=1725202372; darn=nongnu.org; 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=LA4jeEZSXIyNF/wBhldtI2p7w4RNntmuoAerN03i6Nk=; b=toJfdckTZl6sGd76DeZygEuSvr8KO0NtJ0JNwlmSVhKBXYmlYdmj9BEy4bifimtET4 4X+RRSuz+/spgQ/w7g9si7bC/Xn5d9vE3k2/Otr+cFhGvSqertZofw9EF4KwUIy2AZbv nqUuOd/ebaTO3enOPXHPtqI34LPcp199VHrodGVWgIO2W9DCnplLPxgNjVWbLKXXmhUM zLLbALOi0vkdYyEfzA5Vu22pifnEwNhm+cYVLM8YJ0iZLltF5+gI2Uze3PmeuLDv6Bvg 4F+nt6a6MntxovGGoep7pNiwsefVCMI9ejs0zZ+v11GkOBgOKeCfi1OoMWqSCH980zpE +Hag== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1724597572; x=1725202372; 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=LA4jeEZSXIyNF/wBhldtI2p7w4RNntmuoAerN03i6Nk=; b=GOiYK9OEKu9c6JT3o4ojEDIWi3Doqpyj7kJMPlpI3ezAxBO4/KsLhwf4xbmHujBGNG DzBm2nciAgvUM+2DC5cGm9gwgTaWepD/1sBzqq+Qh84YJ0gbbs8OzfHAUg+uG2JwElP6 9xo1usA4fANRRjJeNkE7J9vupG2IE5T8OEV8GS8s7iswLxp76NUTec3n9e4t/H/689xv 1NwDeuz2Ym5ds8y9nKAoSP1TASW0LC4IuUmdfzlq9AAfM2zyP9Bs0uFwi7YKoF6r7hOx yT9BRaxnP1riQhn/iZTHJs+0k4O9rgfJDLd2A1Eq+beI98Go0nDJADJsbKljbNJAaQAf juyA== X-Gm-Message-State: AOJu0YyaVNLWnEx9vRTGlxdVHl+pD/SqiHvulzi0oMvIW59SqZwaUVto t+G7PHcdl6Zsani/7kRD9cVqX/gT4xh56JP+1scXlta1y+m724Mi39HygkX+/oPBlO7bOMbttkN /ZMk= X-Received: by 2002:a17:903:22cd:b0:202:d86:f7e6 with SMTP id d9443c01a7336-2039e53a078mr92747995ad.54.1724597572165; Sun, 25 Aug 2024 07:52:52 -0700 (PDT) Received: from amd.. ([2804:7f0:b400:bb79:3e7c:3fff:fe7a:e83b]) by smtp.gmail.com with ESMTPSA id d9443c01a7336-203b0e164b8sm24698805ad.236.2024.08.25.07.52.50 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 25 Aug 2024 07:52:51 -0700 (PDT) From: Gustavo Romero To: qemu-devel@nongnu.org, alex.bennee@linaro.org, richard.henderson@linaro.org Cc: philmd@linaro.org, peter.maydell@linaro.org, gustavo.romero@linaro.org Subject: [PATCH v3 2/4] gdbstub: Add support for MTE in system mode Date: Sun, 25 Aug 2024 14:52:06 +0000 Message-Id: <20240825145208.46774-3-gustavo.romero@linaro.org> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20240825145208.46774-1-gustavo.romero@linaro.org> References: <20240825145208.46774-1-gustavo.romero@linaro.org> MIME-Version: 1.0 Received-SPF: pass client-ip=2607:f8b0:4864:20::530; envelope-from=gustavo.romero@linaro.org; helo=mail-pg1-x530.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, T_SCC_BODY_TEXT_LINE=-0.01 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 commit makes handle_q_memtag, handle_q_isaddresstagged, and handle_Q_memtag stubs build for system mode, allowing all GDB 'memory-tag' subcommands to work with QEMU gdbstub on aarch64 system mode. Signed-off-by: Gustavo Romero Reviewed-by: Richard Henderson --- target/arm/gdbstub64.c | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/target/arm/gdbstub64.c b/target/arm/gdbstub64.c index 85a19c14c7..9462d3f560 100644 --- a/target/arm/gdbstub64.c +++ b/target/arm/gdbstub64.c @@ -430,6 +430,7 @@ int aarch64_gdb_set_tag_ctl_reg(CPUState *cs, uint8_t *buf, int reg) return 0; #endif } +#endif /* CONFIG_USER_ONLY */ static void handle_q_memtag(GArray *params, void *user_ctx) { @@ -600,12 +601,10 @@ static const GdbCmdParseEntry cmd_handler_table[NUM_CMDS] = { .need_cpu_context = true }, }; -#endif /* CONFIG_USER_ONLY */ void aarch64_cpu_register_gdb_commands(ARMCPU *cpu, GString *qsupported, GPtrArray *qtable, GPtrArray *stable) { -#ifdef CONFIG_USER_ONLY /* MTE */ if (cpu_isar_feature(aa64_mte, cpu)) { g_string_append(qsupported, ";memory-tagging+"); @@ -614,5 +613,4 @@ void aarch64_cpu_register_gdb_commands(ARMCPU *cpu, GString *qsupported, g_ptr_array_add(qtable, (gpointer) &cmd_handler_table[qIsAddressTagged]); g_ptr_array_add(stable, (gpointer) &cmd_handler_table[QMemTags]); } -#endif } From patchwork Sun Aug 25 14:52:07 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Gustavo Romero X-Patchwork-Id: 822362 Delivered-To: patch@linaro.org Received: by 2002:adf:e044:0:b0:367:895a:4699 with SMTP id w4csp1172704wrh; Sun, 25 Aug 2024 07:53:38 -0700 (PDT) X-Forwarded-Encrypted: i=2; AJvYcCVPgxcYeeizsBQ4ntKMPI4MrtTHVfrmU3rbk3YwdnXaEU6exd9nYhN/QQPznmvemCgN1OQNzA==@linaro.org X-Google-Smtp-Source: AGHT+IGbe7WgEPxCLT/A/gI/OhAhGd+wPr44RizWoQUawcVVLl1DloctJq53oOVD/rNaTcW5e+MP X-Received: by 2002:a05:6358:840b:b0:1b1:a8a6:1630 with SMTP id e5c5f4694b2df-1b5c3b30c45mr896509355d.20.1724597617848; Sun, 25 Aug 2024 07:53:37 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1724597617; cv=none; d=google.com; s=arc-20160816; b=qVLGBidZLNsfV6vcgSYvx3NQrFb+FSQLnPsEhXh9z35TxD3h2xksOmh5Jgm3Ucj/WT ZaY+b1vuD6TzF5XiM3IF7sLuvfdiotK/JHHs4ZXxdRSKuewnL66+b5VJeaH4tiY7Nrup APNXv+R/7Cwe5/BGFbu8i6Dt3A4veNh9ZOfQPp5XJIKbnvf0pfnBJLPrQknGRdJZ88T2 76ZbpNsx40f3ZihRlcGrHBZ0VOIgJCsikucS1DpdJEA6/GEIqB6o+FTIpD+WwJi5npmd yMnr47Ws86Ow8sfEmJmQD1wzM/HY9XiyGTzhqA+calFDxBOAmuRP0JbxduDFeCI75pyU borA== 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=NQhqFC3YWlPkCJwXValvIiJxyZnEMyHcDzM+YKLmAFI=; fh=b5q3cJgcc12gnKfUWQQbBLXKRqia4x4Q8oLG+cCF/wU=; b=C9BLq8FjQSjunyzjyoV2MF9l0/R4ZXpY2oi7QnVuFsBSut0E4xxX1t1LKKlfmPyKzm PhwwcM3dAA3AEOm7GWupk0dbwh7KkPw+FJNxBKGpGWZ/peEhgM57nQOcQMCj5C9VAyZE U2FYGuieeAPYd05AmqcKaRdTz+wi7/vEygqCgz4cEDfN9AvSjP5S9gxb2na3xJr/mIZd Noot8eFqowLNTezuBTDEB5iDTEG7fYVME1v2biaYZHHgJC79Gb6BdpqBFR08RItbwyC7 zxqD2QoK4hJTfZXB/0TKLMe+VUfx2b9iHEc/VR/RVROscYCjjEuHRXWkHvg8DwXX8n2H y0Vw==; dara=google.com ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=qOAVfv0G; 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; dara=neutral header.i=@linaro.org Return-Path: Received: from lists.gnu.org (lists.gnu.org. [209.51.188.17]) by mx.google.com with ESMTPS id af79cd13be357-7a67f400046si453235385a.412.2024.08.25.07.53.37 for (version=TLS1_2 cipher=ECDHE-ECDSA-CHACHA20-POLY1305 bits=256/256); Sun, 25 Aug 2024 07:53:37 -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=qOAVfv0G; 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; dara=neutral header.i=@linaro.org Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1siEc0-0002rV-NY; Sun, 25 Aug 2024 10:53:00 -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 1siEby-0002j8-He for qemu-devel@nongnu.org; Sun, 25 Aug 2024 10:52:58 -0400 Received: from mail-pf1-x42b.google.com ([2607:f8b0:4864:20::42b]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1siEbw-0005vb-Su for qemu-devel@nongnu.org; Sun, 25 Aug 2024 10:52:58 -0400 Received: by mail-pf1-x42b.google.com with SMTP id d2e1a72fcca58-7141feed424so2908058b3a.2 for ; Sun, 25 Aug 2024 07:52:56 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1724597575; x=1725202375; darn=nongnu.org; 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=NQhqFC3YWlPkCJwXValvIiJxyZnEMyHcDzM+YKLmAFI=; b=qOAVfv0GtWTKRl/q0MSkhCdxJSuAGef44rQOrCYoTj7mRyPUp7JU9G5KX6msxVsACx r1pJdSCjoViSkv+xoHvi3bfZqTn5F/rFyhsFUxhB4fDqbTISQB2X4hxPc3czbPo9rrPq sNDCBh6F+jo2CB8BVG6smYCdQ4k8/ZZ4L5PdAu3JtO0t3HmCW5AXYpH67Aj0NCrTHCiv Tet1hT4xWSGwM5zn72QgSfGC3Tw8T3vCucoKZPnJyICQzzWZMIQxHRr67kwcZKOijDCv eIHdraalqvfGBQVgm0+ahtmBOTTQfpZJ2TXRWYsjy6EwfGT/h7XdrlBmkuRaIjAdRC0Q l/Ug== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1724597575; x=1725202375; 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=NQhqFC3YWlPkCJwXValvIiJxyZnEMyHcDzM+YKLmAFI=; b=UQ89UvVVAfpE1j/7fce+sMqNAEECKbQRDMyODb7OiMYMkhuehJKvvl20so5gsRiwXw 6bH7gcYaSNjfgrQjeqXkjcRmn75A4X5BOP2tCWl23TfC2bA+vhzvC33rCascBcMB1C06 diADCejmJ2O53RLLAJgFoqpWJpsT3owlLW+FyUf/sTa6YtbwzU/CpaERXuzAM68ydPr0 Dxkt0XcUmdfkEsf8g0BXvYvndSlBYC3AnRXzCmzNZj01+zswTwz67s+FqPBqb3fGnr/O k0Wzc73svdWguWmo6A4U9FKaF6PKWIrvJ3LW3Pen0tSeaY2F0qyxMH0YII5R9PL9DtXg Z/yg== X-Gm-Message-State: AOJu0Yzw2Ys2V1Ez1XTg/mN1MvzG4P5JuyOVX3Y3bmO4MqT4/FF+VnQ/ jJC7e+PoWnEZABt7UyZruYjFnUyckyYjE4vsik5xsCCNTumEbmyGivCq63tHilGJQx6TdTCkjIr 2WkU= X-Received: by 2002:a05:6a21:3a46:b0:1c6:b0cc:c50f with SMTP id adf61e73a8af0-1cc8b49ba5dmr7208201637.25.1724597574608; Sun, 25 Aug 2024 07:52:54 -0700 (PDT) Received: from amd.. ([2804:7f0:b400:bb79:3e7c:3fff:fe7a:e83b]) by smtp.gmail.com with ESMTPSA id d9443c01a7336-203b0e164b8sm24698805ad.236.2024.08.25.07.52.52 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 25 Aug 2024 07:52:54 -0700 (PDT) From: Gustavo Romero To: qemu-devel@nongnu.org, alex.bennee@linaro.org, richard.henderson@linaro.org Cc: philmd@linaro.org, peter.maydell@linaro.org, gustavo.romero@linaro.org Subject: [PATCH v3 3/4] tests/guest-debug: Support passing arguments to the GDB test script Date: Sun, 25 Aug 2024 14:52:07 +0000 Message-Id: <20240825145208.46774-4-gustavo.romero@linaro.org> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20240825145208.46774-1-gustavo.romero@linaro.org> References: <20240825145208.46774-1-gustavo.romero@linaro.org> MIME-Version: 1.0 Received-SPF: pass client-ip=2607:f8b0:4864:20::42b; envelope-from=gustavo.romero@linaro.org; helo=mail-pf1-x42b.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, T_SCC_BODY_TEXT_LINE=-0.01 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 commit adds support for passing arguments to the GDB test scripts so it's possible to parse the args in an "argparse way" in the test scripts launched by the runner. The arguments should be preceded by -- when passed to the runner. For example, passing "--help" arg to the GDB_TEST_SCRIPT: run-test.py [...] --test -- --help The test script should not use the argparse module directly but import arg_parser from test_gdbstub module. arg_parser then can be used just like the argparse.ArgumentParser class: from test_gdbstub import arg_parser p = arg_parser(prog="test-mytest.py", description="My test.") p.add_argument("--vowel", help="Select vowel", required=True, choices=['a','e','i','o','u']) [...] The arg_parser allows a smooth and informative exit if, for instance, the caller of the runner script passes an invalid argument or misses a required argument by the test script. Signed-off-by: Gustavo Romero Reviewed-by: Alex Bennée --- tests/guest-debug/run-test.py | 6 ++++++ tests/guest-debug/test_gdbstub.py | 5 +++++ 2 files changed, 11 insertions(+) diff --git a/tests/guest-debug/run-test.py b/tests/guest-debug/run-test.py index 368ff8a890..5a091db8be 100755 --- a/tests/guest-debug/run-test.py +++ b/tests/guest-debug/run-test.py @@ -27,6 +27,10 @@ def get_args(): parser.add_argument("--binary", help="Binary to debug", required=True) parser.add_argument("--test", help="GDB test script") + parser.add_argument('test_args', nargs='*', + help="Additional args for GDB test script. " + "The args should be preceded by -- to avoid confusion " + "with flags for runner script") parser.add_argument("--gdb", help="The gdb binary to use", default=None) parser.add_argument("--gdb-args", help="Additional gdb arguments") @@ -91,6 +95,8 @@ def log(output, msg): gdb_cmd += " -ex 'target remote %s'" % (socket_name) # finally the test script itself if args.test: + if args.test_args: + gdb_cmd += f" -ex \"py sys.argv={args.test_args}\"" gdb_cmd += " -x %s" % (args.test) diff --git a/tests/guest-debug/test_gdbstub.py b/tests/guest-debug/test_gdbstub.py index 46fbf98f0c..a715c0e3f5 100644 --- a/tests/guest-debug/test_gdbstub.py +++ b/tests/guest-debug/test_gdbstub.py @@ -2,6 +2,7 @@ """ from __future__ import print_function +import argparse import gdb import os import sys @@ -9,6 +10,10 @@ fail_count = 0 +class arg_parser(argparse.ArgumentParser): + def exit(self, status=None, message=""): + print("Wrong GDB script test argument! " + message) + gdb.execute("exit 1") def report(cond, msg): """Report success/fail of a test""" From patchwork Sun Aug 25 14:52:08 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Gustavo Romero X-Patchwork-Id: 822364 Delivered-To: patch@linaro.org Received: by 2002:adf:e044:0:b0:367:895a:4699 with SMTP id w4csp1172806wrh; Sun, 25 Aug 2024 07:53:58 -0700 (PDT) X-Forwarded-Encrypted: i=2; AJvYcCUtdekdy/WZXOx8trKBNI4tEdwhb8noTS0qSqLcr2p4ERC0szVHC+yuu1pnsru+dlasH4Y0tA==@linaro.org X-Google-Smtp-Source: AGHT+IHbMjqimTiTBBFMhfeRU8ekDGOoMCNCx3fx7aV7iCHMy1NADC21lC4tgOrojys6Lb9ZMhmC X-Received: by 2002:a05:6358:4298:b0:1b5:a060:678b with SMTP id e5c5f4694b2df-1b5c20c68f8mr1008901955d.3.1724597638704; Sun, 25 Aug 2024 07:53:58 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1724597638; cv=none; d=google.com; s=arc-20160816; b=wY3MhRjuYb6pzCOv3OdvX77x1TTaC5LRig8dhoqxv9L7zNsfFBpXrvwK3wTv4FIVAf PJydXuv3MSKGO3wpcbK607XhHfDS0Ll8X+rwYEnJfAIv9bE2nMrFYmLV1TX4M/XLp7VD US28EjSFd2osXvgKVMi2gGi6Rkf2jY0EzTofA6x+x3MaMSzWUGpv7q5/BqDFWOdb2qC7 iAfUOp6WVWFiK2SrqmtD+THZdzSJ5Q9DpqLA3k6wsKogv1Klc7ckdg5VvNu0VaGQES2R Ku56tPSFYtBPGpyrk0NdYMoyHz0Z2v1L5CAhT+Cg7b1zoEfpMOQZYz/P5KMRqsOi2fPh cN4A== 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=P4uI/+zEAjeI5zZ34lp5a318ReZmpPSQmnhFszSfJC8=; fh=b5q3cJgcc12gnKfUWQQbBLXKRqia4x4Q8oLG+cCF/wU=; b=jO6tlVQ2+RH3Lj8jvMTd46mZ5Gwi1pxnKsJ4F2ro5fqLGt+JbdkS2KUgWX0eSuV2zs JzzRA2AT/f/5UBf+/ssI9hANX7DT4gROOG+QFQdYpM2+65UqdwOp8KJjkkBzInTbnVtE f4vcEPTc6msGIDGxhCdmuNkdVb6bWq9xhV6iefHVcMRg4TXNkd5bP4HwJUWHv6PWzR+O YwdketX9RzCZiGKVE1t2Au+f8z5sBYPNDzfJAlDMAxhg/OTEY6NNP4rTmHI9psF78U4a aDUlXpNo4nF34danRFd8kZh4zbhIgSZbBoLnBlPA4SM5LTXrLNlgh3x7a3KRbaRcvMCn UMog==; dara=google.com ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=OrOPyCNH; 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; dara=neutral header.i=@linaro.org Return-Path: Received: from lists.gnu.org (lists.gnu.org. [209.51.188.17]) by mx.google.com with ESMTPS id af79cd13be357-7a67f429546si899667085a.626.2024.08.25.07.53.58 for (version=TLS1_2 cipher=ECDHE-ECDSA-CHACHA20-POLY1305 bits=256/256); Sun, 25 Aug 2024 07:53:58 -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=OrOPyCNH; 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; dara=neutral header.i=@linaro.org Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1siEc3-00033M-Pi; Sun, 25 Aug 2024 10:53:03 -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 1siEc1-0002vP-Lo for qemu-devel@nongnu.org; Sun, 25 Aug 2024 10:53:01 -0400 Received: from mail-pl1-x62d.google.com ([2607:f8b0:4864:20::62d]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1siEbz-0005vm-80 for qemu-devel@nongnu.org; Sun, 25 Aug 2024 10:53:01 -0400 Received: by mail-pl1-x62d.google.com with SMTP id d9443c01a7336-202146e93f6so35197005ad.3 for ; Sun, 25 Aug 2024 07:52:58 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1724597577; x=1725202377; darn=nongnu.org; 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=P4uI/+zEAjeI5zZ34lp5a318ReZmpPSQmnhFszSfJC8=; b=OrOPyCNHINKOpWtCOcOmBetL0Qllgfsn39PRtUULgv5aPTyUphEga/YykzDWOm7ApC AznogdXLoYn38FK8QAHTMnVX0P+sVUhJbhoiiQkgValllS9QwJRV2qytCW7vS7UTvv+p rEK0REJ4usmPdameMWiEUeWoNG6JSlZRbopLdYqNQeDd2HVi2ijSH2yhijrdUgz04kr2 89CdQjO9DVc3iLpiql6aqqIgYXO2+y34+pQ23xMDJIxlT+t0f0MU0bvheXt0uAYEFmF4 qAIpj9hlIz0Dn7mEcxfnzaB0OpXjMih2AGPeD1B8SCt39i8v3Vdwl0S6RsAOtzTwMK0I u/bQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1724597577; x=1725202377; 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=P4uI/+zEAjeI5zZ34lp5a318ReZmpPSQmnhFszSfJC8=; b=U5xK1UUurPzgWqxl8rxkmT9sx0KZQl+eruqd79nFvFhv8aGtdPbPcsxL38YvQbl/H7 vQAAJaph5Af/1y7JYp4pWcceVHe0Oc/fGfTtNuX/NrOZjX3jjGC8CmVFzSMduwTKZmm1 EP9+tkasLZL26goBSI+P/txpaqGLiF2scLpAFYgWO1GKNm9zjLqnMhN5KXHjxLjvY9pp BU3ggStzWtoOuL7MPlGTLEMqOwtcOdZ6pTW046/8HoxMjW6miJxQEuU8Ph+WFmHwK+a1 2ErM92dy8QDuAaMUTJrWrVpW4Apa3YejknutSjnahEaDKUPQCLZv40L3XhrnR2XEV432 ss3w== X-Gm-Message-State: AOJu0YzgjaMqtasPfz+7QIZoWPANEtcIEZIsA/TZkhJmOgXFCG/ZaDJk 1fs7GSY8CgG5it2sQB3r2jnpVx7HZLe01rDqnMdEQAN/4DslP1vjlfDzHgjoGsj1lidZuQVm+Yu cGRE= X-Received: by 2002:a17:902:d2c8:b0:202:708:343b with SMTP id d9443c01a7336-2039e55514cmr88117705ad.65.1724597577088; Sun, 25 Aug 2024 07:52:57 -0700 (PDT) Received: from amd.. ([2804:7f0:b400:bb79:3e7c:3fff:fe7a:e83b]) by smtp.gmail.com with ESMTPSA id d9443c01a7336-203b0e164b8sm24698805ad.236.2024.08.25.07.52.54 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 25 Aug 2024 07:52:56 -0700 (PDT) From: Gustavo Romero To: qemu-devel@nongnu.org, alex.bennee@linaro.org, richard.henderson@linaro.org Cc: philmd@linaro.org, peter.maydell@linaro.org, gustavo.romero@linaro.org Subject: [PATCH v3 4/4] tests/tcg/aarch64: Extend MTE gdbstub tests to system mode Date: Sun, 25 Aug 2024 14:52:08 +0000 Message-Id: <20240825145208.46774-5-gustavo.romero@linaro.org> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20240825145208.46774-1-gustavo.romero@linaro.org> References: <20240825145208.46774-1-gustavo.romero@linaro.org> MIME-Version: 1.0 Received-SPF: pass client-ip=2607:f8b0:4864:20::62d; envelope-from=gustavo.romero@linaro.org; helo=mail-pl1-x62d.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, T_SCC_BODY_TEXT_LINE=-0.01 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 Extend MTE gdbstub tests to also run in system mode (share tests between user mode and system mode). The tests will only run if a version of GDB that supports MTE on baremetal is available in the test environment and if available compiler supports the 'memtag' flag (-march=armv8.5-a+memtag). For the tests running in system mode, a page that supports MTE ops. is necessary. Therefore, an MTE-enabled page is made available (mapped) in the third 2 MB chunk of the second 1 GB space in the flat mapping set in boot.S. A new binary, mte.S, is also introduced for the tests. It links against boot.S and is executed by QEMU in system mode. Signed-off-by: Gustavo Romero --- configure | 5 + tests/tcg/aarch64/Makefile.softmmu-target | 49 +++++++++- tests/tcg/aarch64/Makefile.target | 3 +- tests/tcg/aarch64/gdbstub/test-mte.py | 71 +++++++++----- tests/tcg/aarch64/system/boot.S | 11 +++ tests/tcg/aarch64/system/kernel.ld | 7 ++ tests/tcg/aarch64/system/mte.S | 109 ++++++++++++++++++++++ 7 files changed, 227 insertions(+), 28 deletions(-) create mode 100644 tests/tcg/aarch64/system/mte.S diff --git a/configure b/configure index d08b71f14b..40186d865e 100755 --- a/configure +++ b/configure @@ -1679,6 +1679,11 @@ for target in $target_list; do echo "GDB_HAS_MTE=y" >> $config_target_mak fi + if test "${gdb_arches#*aarch64}" != "$gdb_arches" && version_ge $gdb_version 16.0; then + # GDB has to support MTE in baremetal to allow debugging MTE in QEMU system mode + echo "GDB_SUPPORTS_MTE_IN_BAREMETAL=y" >> $config_target_mak + fi + echo "run-tcg-tests-$target: $qemu\$(EXESUF)" >> Makefile.prereqs tcg_tests_targets="$tcg_tests_targets $target" fi diff --git a/tests/tcg/aarch64/Makefile.softmmu-target b/tests/tcg/aarch64/Makefile.softmmu-target index 139e04d15f..59ee662cda 100644 --- a/tests/tcg/aarch64/Makefile.softmmu-target +++ b/tests/tcg/aarch64/Makefile.softmmu-target @@ -2,14 +2,22 @@ # Aarch64 system tests # -AARCH64_SYSTEM_SRC=$(SRC_PATH)/tests/tcg/aarch64/system +AARCH64_SRC=$(SRC_PATH)/tests/tcg/aarch64 +AARCH64_SYSTEM_SRC=$(AARCH64_SRC)/system + VPATH+=$(AARCH64_SYSTEM_SRC) # These objects provide the basic boot code and helper functions for all tests CRT_OBJS=boot.o -AARCH64_TEST_SRCS=$(wildcard $(AARCH64_SYSTEM_SRC)/*.c) -AARCH64_TESTS = $(patsubst $(AARCH64_SYSTEM_SRC)/%.c, %, $(AARCH64_TEST_SRCS)) +AARCH64_TEST_C_SRCS_=$(wildcard $(AARCH64_SYSTEM_SRC)/*.c) +AARCH64_TEST_S_SRCS=$(AARCH64_SYSTEM_SRC)/mte.S + +AARCH64_C_TESTS = $(patsubst $(AARCH64_SYSTEM_SRC)/%.c, %, $(AARCH64_TEST_C_SRCS)) +AARCH64_S_TESTS = $(patsubst $(AARCH64_SYSTEM_SRC)/%.S, %, $(AARCH64_TEST_S_SRCS)) + +AARCH64_TESTS = $(AARCH64_C_TESTS) +AARCH64_TESTS += $(AARCH64_S_TESTS) CRT_PATH=$(AARCH64_SYSTEM_SRC) LINK_SCRIPT=$(AARCH64_SYSTEM_SRC)/kernel.ld @@ -21,7 +29,8 @@ LDFLAGS+=-static -nostdlib $(CRT_OBJS) $(MINILIB_OBJS) -lgcc config-cc.mak: Makefile $(quiet-@)( \ - $(call cc-option,-march=armv8.3-a, CROSS_CC_HAS_ARMV8_3)) 3> config-cc.mak + $(call cc-option,-march=armv8.3-a, CROSS_CC_HAS_ARMV8_3); \ + $(call cc-option,-march=armv8.5-a+memtag, CROSS_CC_HAS_ARMV8_MTE)) 3> config-cc.mak -include config-cc.mak # building head blobs @@ -88,3 +97,35 @@ pauth-3: run-pauth-3: $(call skip-test, "RUN of pauth-3", "not built") endif + +ifneq ($(CROSS_CC_HAS_ARMV8_MTE),) +QEMU_MTE_ENABLED_MACHINE=-M virt,mte=on -cpu max -display none +QEMU_OPTS_WITH_MTE_ON = $(QEMU_MTE_ENABLED_MACHINE) $(QEMU_BASE_ARGS) -kernel +mte: CFLAGS+=-march=armv8.5-a+memtag +mte: mte.S $(LINK_SCRIPT) $(CRT_OBJS) $(MINILIB_OBJS) + $(CC) $(CFLAGS) $(EXTRA_CFLAGS) $< -o $@ $(LDFLAGS) + +run-mte: QEMU_OPTS=$(QEMU_OPTS_WITH_MTE_ON) +run-mte: mte + +ifeq ($(GDB_SUPPORTS_MTE_IN_BAREMETAL),y) +run-gdbstub-mte: QEMU_OPTS=$(QEMU_OPTS_WITH_MTE_ON) +run-gdbstub-mte: mte + $(call run-test, $@, $(GDB_SCRIPT) \ + --output run-gdbstub-mte.out \ + --gdb $(GDB) \ + --qemu $(QEMU) --qargs "-chardev null$(COMMA)id=output $(QEMU_OPTS)" \ + --bin $< --test $(AARCH64_SRC)/gdbstub/test-mte.py -- --mode=system, \ + gdbstub MTE support) + +EXTRA_RUNS += run-gdbstub-mte +else # !GDB_SUPPORTS_MTE_IN_BAREMETAL +run-gdbstub-mte: + $(call skip-test "RUN of gdbstub-mte", "GDB does not support MTE in baremetal!") +endif +else # !CROSS_CC_HAS_ARMV8_MTE +mte: + $(call skip-test, "BUILD of $@", "missing compiler support") +run-mte: + $(call skip-test, "RUN of mte", "not build") +endif diff --git a/tests/tcg/aarch64/Makefile.target b/tests/tcg/aarch64/Makefile.target index 8cc62eb456..9efe2f81ad 100644 --- a/tests/tcg/aarch64/Makefile.target +++ b/tests/tcg/aarch64/Makefile.target @@ -138,7 +138,8 @@ run-gdbstub-mte: mte-8 $(call run-test, $@, $(GDB_SCRIPT) \ --gdb $(GDB) \ --qemu $(QEMU) --qargs "$(QEMU_OPTS)" \ - --bin $< --test $(AARCH64_SRC)/gdbstub/test-mte.py, \ + --bin $< --test $(AARCH64_SRC)/gdbstub/test-mte.py \ + -- --mode=user, \ gdbstub MTE support) EXTRA_RUNS += run-gdbstub-mte diff --git a/tests/tcg/aarch64/gdbstub/test-mte.py b/tests/tcg/aarch64/gdbstub/test-mte.py index 66f9c25f8a..a4cae6caa0 100644 --- a/tests/tcg/aarch64/gdbstub/test-mte.py +++ b/tests/tcg/aarch64/gdbstub/test-mte.py @@ -1,21 +1,26 @@ from __future__ import print_function # # Test GDB memory-tag commands that exercise the stubs for the qIsAddressTagged, -# qMemTag, and QMemTag packets. Logical tag-only commands rely on local -# operations, hence don't exercise any stub. +# qMemTag, and QMemTag packets, which are used for manipulating allocation tags. +# Logical tags-related commands rely on local operations, hence don't exercise +# any stub and so are not used in this test. # -# The test consists in breaking just after a atag() call (which sets the -# allocation tag -- see mte-8.c for details) and setting/getting tags in -# different memory locations and ranges starting at the address of the array -# 'a'. +# The test consists in breaking just after a tag is set in a specific memory +# chunk, and then using the GDB 'memory-tagging' subcommands to set/get tags in +# different memory locations and ranges in the MTE-enabled memory chunk. # # This is launched via tests/guest-debug/run-test.py # -import gdb +try: + import gdb +except ModuleNotFoundError: + from sys import exit + exit("This script must be launched via tests/guest-debug/run-test.py!") import re -from test_gdbstub import main, report +from sys import argv +from test_gdbstub import arg_parser, main, report PATTERN_0 = "Memory tags for address 0x[0-9a-f]+ match \\(0x[0-9a-f]+\\)." @@ -23,12 +28,32 @@ def run_test(): - gdb.execute("break 95", False, True) + p = arg_parser(prog="test-mte.py", description="TCG MTE tests.") + p.add_argument("--mode", help="Run test for QEMU system or user mode.", + required=True, choices=['system','user']) + + args = p.parse_args(args=argv) + + if args.mode == "system": + # Break address: where to break before performing the tests + # See mte.S for details about this label. + ba = "main_end" + # Tagged address: the start of the MTE-enabled memory chunk to be tested + # 'tagged_addr' (x1) is a pointer to the MTE-enabled page. See mte.S. + ta = "$x1" + else: # mode="user" + # Line 95 in mte-8.c + ba = "95" + # 'a' array. See mte-8.c + ta = "a" + + gdb.execute(f"break {ba}", False, True) gdb.execute("continue", False, True) + try: - # Test if we can check correctly that the allocation tag for - # array 'a' matches the logical tag after atag() is called. - co = gdb.execute("memory-tag check a", False, True) + # Test if we can check correctly that the allocation tag for the address + # in {ta} matches the logical tag in {ta}. + co = gdb.execute(f"memory-tag check {ta}", False, True) tags_match = re.findall(PATTERN_0, co, re.MULTILINE) if tags_match: report(True, f"{tags_match[0]}") @@ -39,20 +64,20 @@ def run_test(): # tags rely on local operation and so don't exercise any stub. # Set the allocation tag for the first granule (16 bytes) of - # address starting at 'a' address to a known value, i.e. 0x04. - gdb.execute("memory-tag set-allocation-tag a 1 04", False, True) + # address starting at {ta} address to a known value, i.e. 0x04. + gdb.execute(f"memory-tag set-allocation-tag {ta} 1 04", False, True) # Then set the allocation tag for the second granule to a known # value, i.e. 0x06. This tests that contiguous tag granules are - # set correct and don't run over each other. - gdb.execute("memory-tag set-allocation-tag a+16 1 06", False, True) + # set correctly and don't run over each other. + gdb.execute(f"memory-tag set-allocation-tag {ta}+16 1 06", False, True) # Read the known values back and check if they remain the same. - co = gdb.execute("memory-tag print-allocation-tag a", False, True) + co = gdb.execute(f"memory-tag print-allocation-tag {ta}", False, True) first_tag = re.match(PATTERN_1, co)[1] - co = gdb.execute("memory-tag print-allocation-tag a+16", False, True) + co = gdb.execute(f"memory-tag print-allocation-tag {ta}+16", False, True) second_tag = re.match(PATTERN_1, co)[1] if first_tag == "0x4" and second_tag == "0x6": @@ -61,15 +86,15 @@ def run_test(): report(False, "Can't set/print allocation tags!") # Now test fill pattern by setting a whole page with a pattern. - gdb.execute("memory-tag set-allocation-tag a 4096 0a0b", False, True) + gdb.execute(f"memory-tag set-allocation-tag {ta} 4096 0a0b", False, True) # And read back the tags of the last two granules in page so # we also test if the pattern is set correctly up to the end of # the page. - co = gdb.execute("memory-tag print-allocation-tag a+4096-32", False, True) + co = gdb.execute(f"memory-tag print-allocation-tag {ta}+4096-32", False, True) tag = re.match(PATTERN_1, co)[1] - co = gdb.execute("memory-tag print-allocation-tag a+4096-16", False, True) + co = gdb.execute(f"memory-tag print-allocation-tag {ta}+4096-16", False, True) last_tag = re.match(PATTERN_1, co)[1] if tag == "0xa" and last_tag == "0xb": @@ -78,8 +103,8 @@ def run_test(): report(False, "Fill pattern failed!") except gdb.error: - # This usually happens because a GDB version that does not - # support memory tagging was used to run the test. + # This usually happens because a GDB version that does not support + # memory tagging was used to run the test. report(False, "'memory-tag' command failed!") diff --git a/tests/tcg/aarch64/system/boot.S b/tests/tcg/aarch64/system/boot.S index 501685d0ec..4eb1b35b88 100644 --- a/tests/tcg/aarch64/system/boot.S +++ b/tests/tcg/aarch64/system/boot.S @@ -135,6 +135,17 @@ __start: orr x1, x1, x3 str x1, [x2] /* 2nd 2mb (.data & .bss)*/ + /* Third block: at 'mte_page', set in kernel.ld */ + adrp x1, mte_page + add x1, x1, :lo12:mte_page + bic x1, x1, #(1 << 21) - 1 + and x4, x1, x5 + add x2, x0, x4, lsr #(21 - 3) + /* attr(AF, NX, block, AttrIndx=Attr1) */ + ldr x3, =(3 << 53) | 0x401 | (1 << 2) + orr x1, x1, x3 + str x1, [x2] + /* Setup/enable the MMU. */ /* diff --git a/tests/tcg/aarch64/system/kernel.ld b/tests/tcg/aarch64/system/kernel.ld index 7b3a76dcbf..46f1092522 100644 --- a/tests/tcg/aarch64/system/kernel.ld +++ b/tests/tcg/aarch64/system/kernel.ld @@ -18,6 +18,13 @@ SECTIONS .bss : { *(.bss) } + /* + * Align the MTE page to the next 2mb boundary (i.e., the third 2mb chunk + * starting from 1gb) by setting the address for symbol 'mte_page', which is + * used in boot.S to setup the PTE and in the mte.S test as the address that + * the MTE instructions operate on. + */ + mte_page = ALIGN(1 << 22); /DISCARD/ : { *(.ARM.attributes) } diff --git a/tests/tcg/aarch64/system/mte.S b/tests/tcg/aarch64/system/mte.S new file mode 100644 index 0000000000..b611240a95 --- /dev/null +++ b/tests/tcg/aarch64/system/mte.S @@ -0,0 +1,109 @@ +/* + * Code to help test the MTE gdbstubs in system mode. + * + * Copyright (c) 2024 Linaro Limited + * + * Author: Gustavo Romero + * + * SPDX-License-Identifier: LGPL-2.1-or-later + */ + +#define addr x0 /* Ptr to the start of the MTE-enabled page. */ +#define tagged_addr x1 /* 'addr' ptr with a random-generated tag added. */ +#define tmp0 x2 /* Scratch register. */ +#define tmp1 x3 /* Scratch register. */ +#define tmp2 x4 /* Scratch register. */ +#define tmp3 x5 /* Sctatch register. */ + + .file "mte.S" + + .text + .align 4 + + .globl main + .type main, @function + +main: + /* + * Set MAIR_EL1 (Memory Attribute Index Register). In boot.S, the + * attribute index for .mte_page is set to point to MAILR_EL field Attr1 + * (AttrIndx=Attr1), so set Attr1 as Tagged Normal (MTE) to enable MTE + * on this page. + * + * Attr1 = 0xF0 => Tagged Normal (MTE) + */ + mrs tmp0, mair_el1 + orr tmp0, tmp0, (0xF0 << 8) + msr mair_el1, tmp0 + + /* + * Set TCR_EL1 (Translation Control Registers) to ignore the top byte + * in the translated addresses so it can be used to keep the tags. + * + * TBI0[37] = 0b1 => Top Byte ignored and used for tagged addresses + */ + mrs tmp1, tcr_el1 + orr tmp1, tmp1, (1 << 37) + msr tcr_el1, tmp1 + + /* + * Set SCTLR_EL1 (System Control Register) to enable the use of MTE + * insns., like stg & friends, and to enable synchronous exception in + * case of a tag mismatch, i.e., when the logical tag in 'tagged_addr' + * is different from the allocation tag related to 'addr' address. + * + * ATA[43] = 0b1 => Enable access to allocation tags at EL1 + * TCF[41:40] = 0b01 => Tag Check Faults cause a synchronous exception + * + */ + mrs tmp2, sctlr_el1 + mov tmp3, (1 << 43) | (1 << 40) + orr tmp2, tmp2, tmp3 + msr sctlr_el1, tmp2 + + isb + + /* + * MTE-enabled page resides at the 3rd 2MB chunk in the second 1GB + * block, i.e., at 0x40400000 address. See .mte_page section in boot.S + * and kernel.ld (where the address is effectively computed). + * + * Load .mte_page address into 'addr' register. + */ + adrp addr, mte_page + add addr, addr, :lo12:mte_page + + /* + * Set GCR for random tag generation. 0xA5 is just a random value to set + * GCR != 0 so the tag generated by 'irg' insn. is not zero, which is + * more interesting for the tests than when tag is zero. + */ + mov tmp0, 0xA5 + msr gcr_el1, tmp0 + + /* + * Generate a logical tag, add it to 'addr' address and put it into + * 'tagged_addr'. + */ + irg tagged_addr, addr + + /* + * Store the generated tag to memory region pointed to by 'addr', i.e. + * set the allocation tag for granule at 'addr'. The tag is extracted + * by stg from tagged_addr pointer. + */ + stg tagged_addr, [addr] + + /* + * Store a random value (0xdeadbeef) to tagged_addr address. This must + * not cause any Tag Check Fault since logical tag in tagged_addr and + * allocation tag associated with the memory pointed by tagged_addr are + * set the same, otherwise something is off and the test fails -- an + * exception is generated. + */ + ldr tmp1, =0xdeadbeef + str tmp1, [tagged_addr] + + /* This label is used by GDB Python script test-mte.py. */ +main_end: + ret