From patchwork Thu Aug 8 05:15:28 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Gustavo Romero X-Patchwork-Id: 817705 Delivered-To: patch@linaro.org Received: by 2002:a5d:4e11:0:b0:367:895a:4699 with SMTP id p17csp702694wrt; Wed, 7 Aug 2024 22:16:45 -0700 (PDT) X-Forwarded-Encrypted: i=2; AJvYcCV2+ci1tywaF/9jAiTYogtk6ML6hzhDegjLAvStWeuE6AzMELjEOkeX4tB1raK7ul76gFgUFm24fKU1quZ60/Lu X-Google-Smtp-Source: AGHT+IFCy5AbXbglqnfjZebVtvUHl09ZFiR21M3UaOn2u0Tsn1UFHhTMxBL+/JkwyQnFR5zhytqW X-Received: by 2002:a05:620a:bcb:b0:79d:7e5a:d018 with SMTP id af79cd13be357-7a3817bd648mr86951585a.9.1723094204825; Wed, 07 Aug 2024 22:16:44 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1723094204; cv=none; d=google.com; s=arc-20160816; b=pmsqGpVUYCGWQl03WUaU29hZKsZaPj1en+dq0hsHXJZKzTy3aX63wspvSMeHcQNmYV nFr9yC/AUsO8aTlH7xuVrZJEelbfiSV/ZPrlCHy0jsbnkdHYu1JAPYCZnN2py9Z4d+gQ p2jCca/Iw7c36qMMayhgPcOw97CaUba0Kska76Hl2Y9H2XAg62WxusPE6+3bCkbftwFu 5y2XeeH4jeeM4C2oIakc+8I/w5fEpTfhwX4Qi6SajjLvItZ/mmykAt/g1LsOxNjkS39x GrPAbXOtmwETC7D8jJPWuJ1rQ+TLx0yJWS2fu0byu/pUdrFacRFsVWCRljl7Ecev63f9 uN9A== 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=OsLWShV0KYG63q6ApLyZEwJPcBpjz5iccGdNDN/z9sI=; fh=b5q3cJgcc12gnKfUWQQbBLXKRqia4x4Q8oLG+cCF/wU=; b=DIS9ajpYEzodckAhFRa66eClxU5hVL038B0w7CLYZSA3GpkwF/0hyU759q/2rHK7Sl iq+P1DAo2crNkjKdk2nQppTBki5Bd2SUSyoR+gBqLSj5S/U3QVSc17aRiTk+6rcm/lYS ZnbjpCVxvTOHvRz9Dgm7Fj7pYwd531lqRHahRhz6IqyS4eJg8pTG5ZS+d8yh5yEqL//+ +WbwYyUhUPw+Al55Q8I5wcgYYInzgaUZimT701oCESvN90T+0UoqoGp9XQisFIEdbxbD +llEiK+7lvWP3wcAFG1EnU11uNWHnqYBseni4L5ydPpYVytIU1+0oFx4n+TauUOXJTFZ SaBQ==; dara=google.com ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=a7CfNMmt; 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-7a3785fb5b7si339190485a.75.2024.08.07.22.16.44 for (version=TLS1_2 cipher=ECDHE-ECDSA-CHACHA20-POLY1305 bits=256/256); Wed, 07 Aug 2024 22:16:44 -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=a7CfNMmt; 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 1sbvVJ-0007A8-MH; Thu, 08 Aug 2024 01:16:01 -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 1sbvVF-00071z-KK for qemu-devel@nongnu.org; Thu, 08 Aug 2024 01:15:58 -0400 Received: from mail-pf1-x430.google.com ([2607:f8b0:4864:20::430]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1sbvVD-0002kL-L3 for qemu-devel@nongnu.org; Thu, 08 Aug 2024 01:15:57 -0400 Received: by mail-pf1-x430.google.com with SMTP id d2e1a72fcca58-70d333d5890so581518b3a.0 for ; Wed, 07 Aug 2024 22:15:55 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1723094153; x=1723698953; 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=OsLWShV0KYG63q6ApLyZEwJPcBpjz5iccGdNDN/z9sI=; b=a7CfNMmt2lA0NEBgh0Lo3IZmuikqItU7LBWlaK48eLtYR1A1SkVhPm2lwd24nD5f0w jvMUkpuNWIYS5/Dxh3ZM1GCdgGJFMGaL5s7rFTdblWouFdJNy+ttCG1mjglSxna25B1E F4Fd5Y57Ou6Hubv1LkLsVJ3FYDxPNCxDRtszx4Lh6X2ZZjZU/c5HG+EHwuzdXtWxtPFw RTvDtLkvno0daPqLZvoWlgez+geZDrfiBxStivVCtdWAwNJU6jIDKCX8gw1SyLGT5IuG VZs8EAOtVd/4B3DX/jFFnA4NoETOoW1hffUKGUviMMIDUkKOjFUrhA0GJH1i6L9sk24t lj6w== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1723094153; x=1723698953; 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=OsLWShV0KYG63q6ApLyZEwJPcBpjz5iccGdNDN/z9sI=; b=xKvZyVIaKulz9ags3usGmErvQgxAXH8g6nRNpYCYsVfmOmcZIq+So7xvVHGO4YqaAk hwLqiZtxyGxQIMsXfaKHme7TNdat2nLqGKl7geMRFhy5brUx4W70R0ZSGkEqk1JmMdJH auWPDTBnkb6gxHN5Z+HRZ1I8i5xtZm9WwsJWO1muZaC7SnrAYsi7RFt3eDyziefbQBSn sTd2/o8Bhmj8Glw7opyxL3cwAYm8gzv+zWAgDenN2cY704rx/lD3nvdC0m7QOnOWguYN ZcpHfIU78+gTBGpupmTdkQljvVihPid46Q60p1ZQ6pYa7+33L8fYpOIdDTRmLW3wLm50 tY4w== X-Gm-Message-State: AOJu0YxRyRUFmLeYe/lcAIKJUgskOZ2L6XfC9CImwGrHunwDFxdi/tIe SzJwnZuZbiTNKT9SfMcao4YolRAx7sLRZs735Vt1JELkCEH38PUI3kEzAf/JI/n3YP9mp1iZw6L V X-Received: by 2002:a05:6a00:1aca:b0:70d:2621:5808 with SMTP id d2e1a72fcca58-710cad57928mr1049761b3a.9.1723094153399; Wed, 07 Aug 2024 22:15:53 -0700 (PDT) Received: from amd.. ([2804:7f0:b403:720f:3e7c:3fff:fe7a:e83b]) by smtp.gmail.com with ESMTPSA id d2e1a72fcca58-710cb22a455sm373484b3a.71.2024.08.07.22.15.51 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 07 Aug 2024 22:15:52 -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 v2 1/4] gdbstub: Use specific MMU index when probing MTE addresses Date: Thu, 8 Aug 2024 05:15:28 +0000 Message-Id: <20240808051531.3183498-2-gustavo.romero@linaro.org> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20240808051531.3183498-1-gustavo.romero@linaro.org> References: <20240808051531.3183498-1-gustavo.romero@linaro.org> MIME-Version: 1.0 Received-SPF: pass client-ip=2607:f8b0:4864:20::430; envelope-from=gustavo.romero@linaro.org; helo=mail-pf1-x430.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 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 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..26d242dd63 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) & ARM_MMU_IDX_COREIDX_MASK; /* 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) & ARM_MMU_IDX_COREIDX_MASK; + 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) & ARM_MMU_IDX_COREIDX_MASK; + 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 Thu Aug 8 05:15:29 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Gustavo Romero X-Patchwork-Id: 817706 Delivered-To: patch@linaro.org Received: by 2002:a5d:4e11:0:b0:367:895a:4699 with SMTP id p17csp702705wrt; Wed, 7 Aug 2024 22:16:47 -0700 (PDT) X-Forwarded-Encrypted: i=2; AJvYcCWUuPh4kvQyjuq3VelCd0syw9IQfzwTMG/XmHHugnMVwwWgAyAgacCkcmaPqkshYeEY0C7asSa94xRcmRrr6BGP X-Google-Smtp-Source: AGHT+IGv6SkFJD74/m4FE2Ls95Fwh6aOfaK1zyatvqKCq751fEgYKjqXFkgzW/lieP9zDbqaUn9P X-Received: by 2002:a05:690c:d96:b0:61b:3304:b702 with SMTP id 00721157ae682-69bf7357559mr8147457b3.5.1723094207348; Wed, 07 Aug 2024 22:16:47 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1723094207; cv=none; d=google.com; s=arc-20160816; b=kUPL7rRIyRteqKjhM0alJ+ug9gxw6WCaxPhW4TQTuPz7BpFmMt0oWRNh5o7bObwG28 5rnjidEw9F87F+AYkM97RB5FzuHxezfwtppFFZu1Xr1ea9HTFZMhGav3vFtWhCOkZ3AB +OPL+7e4G659AfehBWg1MoJJcPxp3Wlc/Na8xZYWIAceNHWMq9VxNV8vnev8s9/WbMl2 PdEfgxM6tTQyyS+116GTBXN2FL41scAH6D9lKpKidbGgEsWwsGD0ZzAyj1EtGNq12yl/ mUWZlR6lRHnm5bbDI4LBhc7LTCH9a5pXA2UK2vg+wLjMo21VQAoOdDL/4PYdQISH0Iuo Uhkg== 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=vDvV5wCpIRgzAO2ubNmWFuQnSMmzynNkCt87fmBWnrM=; fh=b5q3cJgcc12gnKfUWQQbBLXKRqia4x4Q8oLG+cCF/wU=; b=zBCDuQanq0y3Ol8r54kZBt3rQHCogiCVKAp/Y4MjjMC/The3n4TKsimrYEq6FC5hGj BglwDiyjTWLDsBQmkeDkhCvxNTENaJ/XXVd8SNp0sGMlK+KqjklAWFSCeJcuXmH21jAy RCRDjAg8WFD5b2M7xYYZBKIRn05p4rqm139V9l/FsnYRyOcxoU0Xlirooy0si7yGIWKC 3t5Y5VXe+rxIqxtfPx5zaEzaU2qNlVDPmSWP+BmGpdtxHmoTmgYPEzH9Lc/bXRkEVKMd vgI7EhSrPbV3etASsccH8TKOMj1MnAs8RxN8aW0QIpUgI2UYlJgyBsUvmwTbBpXPS6+Q QxwA==; dara=google.com ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=HN78YkVv; 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-7a3788434fbsi335173885a.561.2024.08.07.22.16.47 for (version=TLS1_2 cipher=ECDHE-ECDSA-CHACHA20-POLY1305 bits=256/256); Wed, 07 Aug 2024 22:16:47 -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=HN78YkVv; 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 1sbvVO-0007aX-QJ; Thu, 08 Aug 2024 01:16:06 -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 1sbvVH-00074e-C8 for qemu-devel@nongnu.org; Thu, 08 Aug 2024 01:16:00 -0400 Received: from mail-pf1-x435.google.com ([2607:f8b0:4864:20::435]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1sbvVF-0002kY-Mz for qemu-devel@nongnu.org; Thu, 08 Aug 2024 01:15:59 -0400 Received: by mail-pf1-x435.google.com with SMTP id d2e1a72fcca58-70d28023accso561323b3a.0 for ; Wed, 07 Aug 2024 22:15:57 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1723094156; x=1723698956; 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=vDvV5wCpIRgzAO2ubNmWFuQnSMmzynNkCt87fmBWnrM=; b=HN78YkVvRsf6ku9N38bcMkoSloqLZiyjywaiOaP6X+kd18WXERiN3KsGqrqAIMBhyJ sIjYSuP2DlIJXfDVL10vnFaMulmzyZRYdc4dkkhGwPUkugkMmcnqBLv5QDMf0U1qrTTd QbZs2ov7bXvxwCR04Io0v8atYbgFibfzvaYlIC06QdVzwVV8TSc+tps6Xrj30J4rgwH+ +J3K2uFd1tq5heDeDbGDx/SSGdHGAPNWao2RuLszXX+3MOY2zBlgcNmkrmfueeBVhInw Js0aKoKSyZDoC1SmHBc77ms1ZKG9J02dbw+OShhPGECsqkfVZsFeZecXw4Fn8tYnN8k/ 54Qw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1723094156; x=1723698956; 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=vDvV5wCpIRgzAO2ubNmWFuQnSMmzynNkCt87fmBWnrM=; b=qPj6a7OxWq8Xd0L3h5tf5444YhXtrhAwcGhctdwjc8vieeQaejGGEl4IF33plClu2j aHDAPe+vdT0LqNpWf5CWqZhn/B6adn+mFYbvrYjjoZo9UW2y7ahdqoG+wOdRmv0I6/ih 38GwTX5sn5fl2ikqJKrfqgJk+2pVuozhHHhTmLrswBLYDZ83JsLXMqmZ+adKRDuUxwWz 78IZkrNtR5WzuFyfGO0wfHK1t4iU7aHn47dYACRgK3FzoeKQTLodKYkIhIz9jr5djfWz Q4sohU9tSZjQ5DOhj347ObVFde397nCdTuA3z79PwUJkOOwECTxn8sscg+r7D37zbgZv KATw== X-Gm-Message-State: AOJu0YwawkxrUQo25nwItq/5f2MV96W1aU+B33Ax6pF+ZlpPflN9RwQ7 LDVpvkdlF3fv/usvxudIxYlQQzm5g/Zqb1cjLjKpW4OKSWYX2ShozHUlXTjH3mW4hjfrsNePIuI 3 X-Received: by 2002:a05:6a00:22c2:b0:70b:1d77:730a with SMTP id d2e1a72fcca58-710cae75777mr1117034b3a.28.1723094155849; Wed, 07 Aug 2024 22:15:55 -0700 (PDT) Received: from amd.. ([2804:7f0:b403:720f:3e7c:3fff:fe7a:e83b]) by smtp.gmail.com with ESMTPSA id d2e1a72fcca58-710cb22a455sm373484b3a.71.2024.08.07.22.15.53 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 07 Aug 2024 22:15:55 -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 v2 2/4] gdbstub: Add support for MTE in system mode Date: Thu, 8 Aug 2024 05:15:29 +0000 Message-Id: <20240808051531.3183498-3-gustavo.romero@linaro.org> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20240808051531.3183498-1-gustavo.romero@linaro.org> References: <20240808051531.3183498-1-gustavo.romero@linaro.org> MIME-Version: 1.0 Received-SPF: pass client-ip=2607:f8b0:4864:20::435; envelope-from=gustavo.romero@linaro.org; helo=mail-pf1-x435.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 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 26d242dd63..0f42855763 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 Thu Aug 8 05:15:30 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Gustavo Romero X-Patchwork-Id: 817703 Delivered-To: patch@linaro.org Received: by 2002:a5d:4e11:0:b0:367:895a:4699 with SMTP id p17csp702647wrt; Wed, 7 Aug 2024 22:16:32 -0700 (PDT) X-Forwarded-Encrypted: i=2; AJvYcCX/5DMyFKG0tb7DVIEp306yUnBrlcDBoKxU/DnFxgSCz4Za5FIQjWnx/WkGip76syf1sHgVfF8d++eaze0AtoyJ X-Google-Smtp-Source: AGHT+IEwyOmbsfW0F62EDd/hf8lypLBKeY+Ywnsg60SqTMqA557G5udGII7P9BWhAqLXQXIEKf1H X-Received: by 2002:a05:622a:2591:b0:447:eb4e:7cc1 with SMTP id d75a77b69052e-451d42c9b1emr10639211cf.44.1723094191912; Wed, 07 Aug 2024 22:16:31 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1723094191; cv=none; d=google.com; s=arc-20160816; b=ShRzeJAdE4EEbTP8ZN7cl1hNZ0+gN8joFs6TiTkqUbPWN/D7LmulGHGCVhxPTZV3d9 rXUVRyO4MryT7n09rSv/two0pIzJW1rRxcADkgMgncLzG7tde8K3DsbGzCsv+zpUZHlp TchQJNOJsnX+Y+VAjq9vMo8DdNuCX0HgWAeVo98zpbQSWN++Hn5kwtmFaKx3xjI/Xx2a lhlYXyor/biBpvCS2Ttd4z3Y7JN8x5WlVSBi+X250lg9yNLGQGJ0404CcMirEtl+hy6A BBUWMPuD4XCuqzFB50sARxRI/K7rk/wgPtBs+hEQtspTFP5rn3AlZrH0MUOaqqHqwIvb moGA== 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=nEsTn/dVAZz0iwGzBqd7pyQcg7bnCq6h6rLTUSpEI7ZlKQfmbPA6zqPO0dlVvyQLun R3u87tDYX/RWoF9qMR9kxEjK6ZfgWjFhcYQZ0TRJEDIKG4Bg6AKOHoHwQ8Ia5U1OJ61a OXGAV+q6tM20FA97HtbDwA24H3AAgZCyXplEWvm0uevwe07tNLu2gmmBTBggqhDsaZVR ltcxrI5+v765xJjERooE99JnBr1837t9487VIQyFLxfvyJ/eqWHleRcgqNEEmfTLp/pG /CTrD11PLluyoKj4gt4VE7tvId9WxhT+6LSGT9UAtxucD9R3Z5e2/UZPnusipS2aM3wG GLvw==; dara=google.com ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=eCx0V04r; 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 d75a77b69052e-451c87020b9si32754301cf.93.2024.08.07.22.16.31 for (version=TLS1_2 cipher=ECDHE-ECDSA-CHACHA20-POLY1305 bits=256/256); Wed, 07 Aug 2024 22:16:31 -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=eCx0V04r; 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 1sbvVM-0007Kc-Tr; Thu, 08 Aug 2024 01:16:04 -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 1sbvVJ-0007Bw-Tm for qemu-devel@nongnu.org; Thu, 08 Aug 2024 01:16:01 -0400 Received: from mail-oa1-x34.google.com ([2001:4860:4864:20::34]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1sbvVI-0002kn-6N for qemu-devel@nongnu.org; Thu, 08 Aug 2024 01:16:01 -0400 Received: by mail-oa1-x34.google.com with SMTP id 586e51a60fabf-26b5173e861so21012fac.3 for ; Wed, 07 Aug 2024 22:15:59 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1723094158; x=1723698958; 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=eCx0V04rkwT9b16jvVjxvaW5FBDRwO5mvPW6ktXKLjBJk7GX9XePD8ZX2d9FOkwFk+ hvXP0LpmhxN6LNPBP1dJplc7N5kxC2QcQYmjKyOWBFni2DQ4smOCBL7f1xPwp2lfZkF9 AF26Q7SCuLLy/vhKCX+PoTZ3vj77K93IA5ZxQi7kDGjM/fP+14qfWCK4Y10WrY+ZtgSi VqhwxfKX6jWu1zcbvIpwZcrYYjmKKZfErIq3qaXPbRiQxThoLtORij6tbbALKeRNyVn8 0vcV52VUPrqXA39zVWlOz47qztCNochJ9VBAIex4mLNr8KCq6IQxNZ20WDhH6VvioMyl oWBg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1723094158; x=1723698958; 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=LWunTizAnY1MtqSnS0JAPgEozKahJjuUhLR3WGFwY3JTTW/RJ4NIKx2nY06zg0ea+z 6cNfZmcXtuBZTlfLNvIx6gwFpR5XJrbpzqq5+fO5wf6+LsXCpz6ynQWJ+tUCJgZNMtUf YkVgqGb6n60pq1oDYBjHLvxML+uQqfDXB2S0RX8mr7UeTK3LtQWBJ0wmM33R299zoj95 sB1eBFtvFdBHRD0BYPQ8o4Gh2pLYPLgWDQcADk9u84tr2LaG48Ybyt5eMZRTBmxduUf9 heP5dlaSJE0O+Qf5B2RyEj+hpmiwjlLICgJeBhyDPUFrvgUgOVGxcJaKpgFIXQ91givU ferA== X-Gm-Message-State: AOJu0Yy5gdy9IOjlyqdoAmy1Li7AZHzWFTozgy3/rDfmljouOnckhVDK uryY6NY8V++WnmfzQcJXP7Mg+C3qw3fcSsakgPnXsKGKzA5xCH3pEvysqcGRCuniFdeEV2t0y+N 9 X-Received: by 2002:a05:6870:4191:b0:260:fd20:a885 with SMTP id 586e51a60fabf-2692b6aa2ccmr961277fac.27.1723094158266; Wed, 07 Aug 2024 22:15:58 -0700 (PDT) Received: from amd.. ([2804:7f0:b403:720f:3e7c:3fff:fe7a:e83b]) by smtp.gmail.com with ESMTPSA id d2e1a72fcca58-710cb22a455sm373484b3a.71.2024.08.07.22.15.56 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 07 Aug 2024 22:15:57 -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 v2 3/4] tests/guest-debug: Support passing arguments to the GDB test script Date: Thu, 8 Aug 2024 05:15:30 +0000 Message-Id: <20240808051531.3183498-4-gustavo.romero@linaro.org> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20240808051531.3183498-1-gustavo.romero@linaro.org> References: <20240808051531.3183498-1-gustavo.romero@linaro.org> MIME-Version: 1.0 Received-SPF: pass client-ip=2001:4860:4864:20::34; envelope-from=gustavo.romero@linaro.org; helo=mail-oa1-x34.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 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 --- 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 Thu Aug 8 05:15:31 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Gustavo Romero X-Patchwork-Id: 817707 Delivered-To: patch@linaro.org Received: by 2002:a5d:4e11:0:b0:367:895a:4699 with SMTP id p17csp702704wrt; Wed, 7 Aug 2024 22:16:47 -0700 (PDT) X-Forwarded-Encrypted: i=2; AJvYcCUjnYJEsbxhlce/WZtUC3HESjJOhGxUH9xLLyHqD1zp6HSq0MTxCwdsyGGUGtdx855qjXRmJUK5AFAiFFY67GE7 X-Google-Smtp-Source: AGHT+IGRLzEglwHsP+HBPId4WzVYXZZyOexNk2ApIQ61k3rfoQcbYxOjuyJPcRHduyuXfCwqQFii X-Received: by 2002:a05:690c:2902:b0:62f:aaaa:187a with SMTP id 00721157ae682-69bf7dfc9d8mr7679467b3.14.1723094207301; Wed, 07 Aug 2024 22:16:47 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1723094207; cv=none; d=google.com; s=arc-20160816; b=IBuPruD3j1oMGVIu2HSgXy9K1+CAbKX244Ndjc7QtJi/+jv+qTWEp0uFOOHF6/Z/2u CPAHYwh6/UuuPzst4UT2A6EJ/9rfgLOaHhNLQEGG5SPKLTKDnUv8LOvKo3jR6jnhIijF vbBi8kd35Ht2ijNxCT4x1FYHCiZmdSqTzYWfxJyLgRKiSvphP0MWBViQ3YUZAxesRvws YKcIvnymy+U8gjPK/bsq8BJsxv6NkbX0/4XKQSZMGz9p1jlWWok3oynhlPTXS+VSFd6Y G1bmZjRMvSoJ92Drq3VRTyr+/UIL4mDI8UfGwWvpIpSDI1ZEdyPtKHBqgpWSREfBfB6L h1lQ== 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=gsF2VtZzhIp4l3JrUYQLqzb3x3L3MgiJGheFj55+C88=; fh=b5q3cJgcc12gnKfUWQQbBLXKRqia4x4Q8oLG+cCF/wU=; b=gcTO4me3QB8QO+gjHvGC2p0WpBY//+MJ0Nci7xGVgUf+D8p0ZfLoTkOTKvUTb1k2xw 0eNHqW49KngWrH/E9fPCRD/WwR2t/873j/8js+GH+BLPHnWtrqyx6/NeUlFFj8s9dWGy zjELjHo90WM/L932bzNFcYPKl9ET4U4db337C5635jO+EqM5hssb9enrb6Uc1SklexxK etuRtEkXc/3fcIAgCCLi+XmIt2gY+WDQmqXE7DfJPj9xPZAjmMmQp3YEKI1ZTlfp6ILq TtTTIoaSr5scVz3Mvneqwyyp8oJpS6tVq7iqWgpi7ULkSzWftK1IXdHJeNUIHAsa/hKj gucg==; dara=google.com ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=CIgJWyvi; 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-7a37ffb0887si89612185a.584.2024.08.07.22.16.47 for (version=TLS1_2 cipher=ECDHE-ECDSA-CHACHA20-POLY1305 bits=256/256); Wed, 07 Aug 2024 22:16:47 -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=CIgJWyvi; 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 1sbvVP-0007eX-Ld; Thu, 08 Aug 2024 01:16:07 -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 1sbvVN-0007Wh-Vh for qemu-devel@nongnu.org; Thu, 08 Aug 2024 01:16:05 -0400 Received: from mail-il1-x136.google.com ([2607:f8b0:4864:20::136]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1sbvVL-0002lC-G7 for qemu-devel@nongnu.org; Thu, 08 Aug 2024 01:16:05 -0400 Received: by mail-il1-x136.google.com with SMTP id e9e14a558f8ab-39b0826298cso2367035ab.2 for ; Wed, 07 Aug 2024 22:16:02 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1723094161; x=1723698961; 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=gsF2VtZzhIp4l3JrUYQLqzb3x3L3MgiJGheFj55+C88=; b=CIgJWyvibOPPiSXuiy5nNw0L7jmsxkKeJ2ZB/R/d+5JJ/0/8SY4FiMjUgGXgpbxWUM xUjOrwJ0sqKek14bS4QdJkEHIkHsJnFRPxT0qfPDNUa16lb+Jgvs5DP01nGYGV3MsPCH fZZD+/lNYXxc99LljHbL0eGbZzw4RC5G9pUO0jdiyGnB9bGGVWwZAXNGhu7lFi8cV4ne 3L2/CXxmc40Wqo0vp9zVfHJAFJr6Aygn8Ees/fo4zQumlsF3ltTtcavuWwX9I38gqDI1 I57N/NRWNLnkTZK3HpHewP/hlvAkVZZCzy8U4kVGx77/1Mehe1sJwYUTwD3NAOnGiPAE OkCA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1723094161; x=1723698961; 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=gsF2VtZzhIp4l3JrUYQLqzb3x3L3MgiJGheFj55+C88=; b=M91G1oH8Stxg5JVIefXQBCSPmgn5aoCVa3njVVGhbyjv3Lw1m4imy7znmMxfQgKqLf +H4Vzh5eMMX1tFSz2/VfeJorMWTqo7aBpPCAsrcI6rWP0D44WsS5qRLNy/LBxs07FYeM WdDsIg/1YR2HcY2l6j+jUWMqLnzvmS00nwV529nM6IgPWbqPFNAVq+5gmiL+mE3e5BG0 8cdBlqOQHg01XjRY3Rzg+Z4fZR8lB3gNik+FEa0RixIUJHgWkSPPkWDFmiI68OuSx03N x7WYHN6OJExIN1f6A7FK6SbnsP+NUTo/Vm7oiNB2YXZc/ikL/DKjnfzMPq+neXS5g4an du3w== X-Gm-Message-State: AOJu0Yz49R6KiKG45R7OTKDCuu3sKuCq1w/tnb6I9ZdRRy23tDw0oOyv z4ZmZ66i4yECGPhBHAzvE/caPwsXx1ds6iHQGDu2vndZBAccEbjFElB3gIB0+jT+RQEmxNdYuk8 x X-Received: by 2002:a05:6e02:1a88:b0:39a:ead8:3170 with SMTP id e9e14a558f8ab-39b5ed2c735mr7991415ab.19.1723094160749; Wed, 07 Aug 2024 22:16:00 -0700 (PDT) Received: from amd.. ([2804:7f0:b403:720f:3e7c:3fff:fe7a:e83b]) by smtp.gmail.com with ESMTPSA id d2e1a72fcca58-710cb22a455sm373484b3a.71.2024.08.07.22.15.58 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 07 Aug 2024 22:16:00 -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 v2 4/4] tests/tcg/aarch64: Extend MTE gdbstub tests to system mode Date: Thu, 8 Aug 2024 05:15:31 +0000 Message-Id: <20240808051531.3183498-5-gustavo.romero@linaro.org> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20240808051531.3183498-1-gustavo.romero@linaro.org> References: <20240808051531.3183498-1-gustavo.romero@linaro.org> MIME-Version: 1.0 Received-SPF: pass client-ip=2607:f8b0:4864:20::136; envelope-from=gustavo.romero@linaro.org; helo=mail-il1-x136.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 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 | 14 +++ tests/tcg/aarch64/system/kernel.ld | 5 + tests/tcg/aarch64/system/mte.S | 115 ++++++++++++++++++++++ 7 files changed, 234 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..79a2ada74a 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: .mte_page */ + 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. */ /* @@ -239,3 +250,6 @@ ttb_stage2: stack: .space 65536, 0 stack_end: + + /* .mte_page location is set in kernel.ld. */ + .section .mte_page diff --git a/tests/tcg/aarch64/system/kernel.ld b/tests/tcg/aarch64/system/kernel.ld index 7b3a76dcbf..7c00c1c378 100644 --- a/tests/tcg/aarch64/system/kernel.ld +++ b/tests/tcg/aarch64/system/kernel.ld @@ -18,6 +18,11 @@ SECTIONS .bss : { *(.bss) } + /* align MTE section to next (third) 2mb */ + . = ALIGN(1 << 22); + .mte : { + *(.mte_page) + } /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..e916ed53b4 --- /dev/null +++ b/tests/tcg/aarch64/system/mte.S @@ -0,0 +1,115 @@ +/* + * 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 + + /* + * See boot.S for details on the attributes set for this page and + * kernel.ld for where its location in memory is set. + */ + .section .mte_page