From patchwork Tue Sep 10 17:38:56 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: =?utf-8?q?Alex_Benn=C3=A9e?= X-Patchwork-Id: 827033 Delivered-To: patch@linaro.org Received: by 2002:adf:ab1c:0:b0:367:895a:4699 with SMTP id q28csp430683wrc; Tue, 10 Sep 2024 10:40:35 -0700 (PDT) X-Forwarded-Encrypted: i=2; AJvYcCWN86v0g+IXT2XCwp2p2MZpT49O2lVTniNQstbeYtAkWZeYyLeexMD+VxI42Q9nEcHVLLahMg==@linaro.org X-Google-Smtp-Source: AGHT+IHqgth0f9qOOg52sFTVDC3Xu5l+/pIZd8/ZysAc9sDlTNIlbydtTMJ03h8MZmBREkXrqmQC X-Received: by 2002:a05:6902:c0c:b0:e1d:2fce:162a with SMTP id 3f1490d57ef6-e1d349f114emr16094102276.39.1725990034871; Tue, 10 Sep 2024 10:40:34 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1725990034; cv=none; d=google.com; s=arc-20240605; b=Zby27F9xGh88wb16r5930k5cr/feeu2sxy1vZ3Gc4BE8RhTFZw2F6ZpZaN+/y7lYDv G0+RRFtOEx4qqdobLHjatfoekkQnzI1JGm8b9pA33JlCE3k56xgQvbyellGmdjJp4IIu Eqytbekr5Ng++bVh/Ejd1Ym+z5uHwOWox9Z0DUhyAb5zROjOwz7Kt87IzOXOcyNC5mP1 /bYttzf2K49J4kMsodumXfVDk5ntsokY13Wm7TAIOnwQCLZIAKQXlXGe91WdE50HdeeE gl/ucRNncUScCVRxZ9GHDAHLTbAlbAINf9ARhAjOZHCbiVRxVJOEdyED01N+f1WtkLgm 7SzQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20240605; 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=4x/2lUUGLpLRO+8rqUP/+rQmXa+2LMUSZP6UGcSNzgE=; fh=h773y6AOAE/ukr4mRlwaH0i0lfsEFb3Q85tR2q3kvZo=; b=Vpcp6C2NKYED/wq+mWL71pwJMNGlGzPeCC5S5rCjQn9J0saaI9eVyevVCPzIg/nOf+ 7jC1vC5qLeOb8kWvJHcE5BnTvQIIAtoD3EmDAvdsdIlg+HR7R4mrtDEa5PIPmbT1g1uQ M+PxNOZBaZT52LE4eLk0R+IqVMv/ByYXFn90F57v5zxttyZsKPdVcVRegh8DQLvRxv4/ iYrgNQalAFSzsRStLCqIdXnEiFUlHIQOCHI3OG2LqjJch8ZWKlNYamMgMYsS4qp1ZQ0n Jh60gYwJCzlPiMxDUOnOulqDonzRWy0qDw3ZO4mTMKTTX5DJPnQFfkZ2SmwuuKsSgzXw J7Jw==; dara=google.com ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=pmJuufhh; 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-45823028974si79721841cf.795.2024.09.10.10.40.34 for (version=TLS1_2 cipher=ECDHE-ECDSA-CHACHA20-POLY1305 bits=256/256); Tue, 10 Sep 2024 10:40:34 -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=pmJuufhh; 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 1so4ps-0005lK-CU; Tue, 10 Sep 2024 13:39:28 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1so4pa-0004mi-TY for qemu-devel@nongnu.org; Tue, 10 Sep 2024 13:39:11 -0400 Received: from mail-ed1-x534.google.com ([2a00:1450:4864:20::534]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1so4pY-0004a2-43 for qemu-devel@nongnu.org; Tue, 10 Sep 2024 13:39:10 -0400 Received: by mail-ed1-x534.google.com with SMTP id 4fb4d7f45d1cf-5c3c30e663fso1197774a12.1 for ; Tue, 10 Sep 2024 10:39:07 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1725989947; x=1726594747; 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=4x/2lUUGLpLRO+8rqUP/+rQmXa+2LMUSZP6UGcSNzgE=; b=pmJuufhhEeVxIgHBm7w4URAbm6RtYPrSVCPuWAn/9GBnp4Oprj1hX81QfFx0mUDjDF XwM/0H23UBMpUkitPnN7avyBrvYJjRoMEijKJkqgmp6fcnVqscgaBBR8YONIQa0U97AQ 3bcAlk++I31kvqUVnFM2MzPWiawZiKs8hvpeV4ec3aQ/mMYUK3QLc/UWLzLT30+5YWQ0 pC7u6Q7dGLHtZEsOyAlXneOrqqbdq3XzGBDtkiWXJaJFL89oMkJz7EY8d8lkf5z7ZYQp 8LnDVLAg2xPmUfuIMSKNV4R/xJbWoT0eiNu4wpAV2fq1ZoQdeBh4bt8X/e+7Dwl46KDn J6VA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1725989947; x=1726594747; 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=4x/2lUUGLpLRO+8rqUP/+rQmXa+2LMUSZP6UGcSNzgE=; b=IRO9/zCWTvnsCU9QE+D+n6R1l0V34BbDbjSXuULlLWjKMl8patiETyWpEHBPDEMcPj EOj47UiHIeQ+gnjrJVJoW6/OagFakRU5HJvC1mHkMlKlm9KRVyZP/SsCj0QaxAfUuXA4 +vg5P89/S2V/RUwNJBvc0xMzYRuwkBJFZwKErnCBTH8lTDmrl8E8yxsAj5QAk2Z+rfun +xuzec54qbFlQp7dlN6YHnv9lzyXmwpOnDH2I9AMjpaX0RbU4d9quhujchvi3kSKgRGj dVsBgEBpXMxEszZsr8awehx/030Ua9R1Q5mqhHctkTmqiqNe81rAZODEt2hvadZTx2u9 irXA== X-Gm-Message-State: AOJu0YxLMj/ucniJKnQgih/K8KY6xyxnEoL2+gu1WHOhWBPKJ9QqzUOd FnhhWjBIXbCRQu4UaoDgU83uXDXVkG/rFtvaJzoo7Sjdu76hohm1H6hhNidh6oY= X-Received: by 2002:a17:907:f15a:b0:a8d:5472:b591 with SMTP id a640c23a62f3a-a900478ee2bmr34753866b.5.1725989946510; Tue, 10 Sep 2024 10:39:06 -0700 (PDT) Received: from draig.lan ([85.9.250.243]) by smtp.gmail.com with ESMTPSA id a640c23a62f3a-a8d25c624efsm507008566b.114.2024.09.10.10.39.02 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 10 Sep 2024 10:39:04 -0700 (PDT) Received: from draig.lan (localhost [IPv6:::1]) by draig.lan (Postfix) with ESMTP id 05B555FA08; Tue, 10 Sep 2024 18:39:01 +0100 (BST) From: =?utf-8?q?Alex_Benn=C3=A9e?= To: qemu-devel@nongnu.org Cc: Thomas Huth , Zhao Liu , Peter Maydell , Paolo Bonzini , Marcel Apfelbaum , qemu-arm@nongnu.org, devel@lists.libvirt.org, Pierrick Bouvier , Alexandre Iooss , =?utf-8?q?Alex_Benn=C3=A9e?= , =?utf-8?q?Philippe_M?= =?utf-8?q?athieu-Daud=C3=A9?= , Jiaxun Yang , Beraldo Leal , Eduardo Habkost , Richard Henderson , Mahmoud Mandour , Yanan Wang , Wainer dos Santos Moschetta , Gustavo Romero Subject: [PATCH v2 06/10] gdbstub: Use specific MMU index when probing MTE addresses Date: Tue, 10 Sep 2024 18:38:56 +0100 Message-Id: <20240910173900.4154726-7-alex.bennee@linaro.org> X-Mailer: git-send-email 2.39.2 In-Reply-To: <20240910173900.4154726-1-alex.bennee@linaro.org> References: <20240910173900.4154726-1-alex.bennee@linaro.org> MIME-Version: 1.0 Received-SPF: pass client-ip=2a00:1450:4864:20::534; envelope-from=alex.bennee@linaro.org; helo=mail-ed1-x534.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 From: Gustavo Romero 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 Message-Id: <20240906143316.657436-2-gustavo.romero@linaro.org> Signed-off-by: Alex Bennée --- 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 Tue Sep 10 17:38:57 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: =?utf-8?q?Alex_Benn=C3=A9e?= X-Patchwork-Id: 827036 Delivered-To: patch@linaro.org Received: by 2002:adf:ab1c:0:b0:367:895a:4699 with SMTP id q28csp430831wrc; Tue, 10 Sep 2024 10:40:52 -0700 (PDT) X-Forwarded-Encrypted: i=2; AJvYcCVKNn5FoJNg5IvZcBMpZQwSoDXp+pRCqfBhYqHWHWpIPz+hFcWi2jL9fMj+cjBehH1IHPl6RQ==@linaro.org X-Google-Smtp-Source: AGHT+IEo//YOWRQ2zXyy45WzLjoQhj0xQFxH+2dIFPd0ubZs0EdyX6xsEHldwlNwMwk2mmZBWv2s X-Received: by 2002:ac8:7d0a:0:b0:447:f4f6:7a1 with SMTP id d75a77b69052e-4580c76c63cmr198783651cf.52.1725990052026; Tue, 10 Sep 2024 10:40:52 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1725990052; cv=none; d=google.com; s=arc-20240605; b=SutJiVxRMzpLB9dsSS0eMmv0q8sYOMLRVTHOFGPkLOY7jEn2aWpqtd+zPVrFSyJzXK PwqLe1aFwmG3b30GPRb98U817l6e9MsWI1HEVGAJBOMT/9eRipHUnHCiGHtWwsnZfkbX ax7WprEzXYaGSS2C5qvmDuldiF9wZE5ng/5uWhd472Aq/tXa3gkay/feVe01bu6m6Ton xYfmri+chvS3wuf7V64lbCr6wqr9HZ3kqBbZTy5FdVpRr3OzhmiA0XA/C+g6gmxuR4Hz ENq1hWHUdRgmFYXnQVLhpOJcXjNV0KMFnC+V4DhYD7FPOXlxRDH2LHdC4Yu0RVkeM+rd XwUA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20240605; 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=4JYCYUJifJOf8IAr8uZJXdISd8++rwC9FrhK6nCyU7M=; fh=h773y6AOAE/ukr4mRlwaH0i0lfsEFb3Q85tR2q3kvZo=; b=BY45pc+X+P3l++ANRr0b/fqoLlFd+kquflk+MP4bACaTh/spfzO4Rhe7msey/uqime tblmk+hsZijmozBAz2vyyVzVHN/VnIkV6cVfPwoh811764QVIaVQiFQcGnBiQ1gbYxwa 92bsECA7AN/y84vrYLRQ/8IOk60BIMPWdvuqRADMKBnxbM9KXtNA2d22HWWLsdF9/qzx 6f614Zb82AevHXasAWW+rBuZYiSFtZSgrd/uLewcFJqGcOy35/OIfY2xCRT/vXBS1LvB g/PMCu7uOZ2tsVIVsCU9HrbGUqEYnrSgCWdIbmqWm3tF6IpEQoIMcxxHe7BigbYOK0M/ T4aw==; dara=google.com ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=pzDz8okp; 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-45822faf96csi82129971cf.584.2024.09.10.10.40.51 for (version=TLS1_2 cipher=ECDHE-ECDSA-CHACHA20-POLY1305 bits=256/256); Tue, 10 Sep 2024 10:40:52 -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=pzDz8okp; 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 1so4pw-0005pY-5Y; Tue, 10 Sep 2024 13:39:32 -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 1so4pc-0004pw-5u for qemu-devel@nongnu.org; Tue, 10 Sep 2024 13:39:13 -0400 Received: from mail-ej1-x62c.google.com ([2a00:1450:4864:20::62c]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1so4pZ-0004ak-OI for qemu-devel@nongnu.org; Tue, 10 Sep 2024 13:39:11 -0400 Received: by mail-ej1-x62c.google.com with SMTP id a640c23a62f3a-a8d29b7edc2so474940166b.1 for ; Tue, 10 Sep 2024 10:39:09 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1725989948; x=1726594748; 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=4JYCYUJifJOf8IAr8uZJXdISd8++rwC9FrhK6nCyU7M=; b=pzDz8okpSnvB5sZALhzWB4nYHRQVcicma5IhzJylcfpfDfuGaDrPtk2rr6dUjTo4pK cCU6WufHroT/s6Pch9cLsUN5o2cA78sN1D9CcZOaibRx1+tcaR0lLcZfQ+dlnRUvabpF CVNcujBvNemihuc9gf6K6k72CHJvO1la6xqSYigL+YdbEP3deNBGuqIrQeEdhXVLH40z AB9EMTyphn6jubOeQ20nnaUMFsRmnSheZmF+ZyZHfMk1I0Ig3vjYg+7WBtUqVRDWlYdP l08wxCaP2dI6qBNgD5wz/6oHyo2Figa3nemIiv3uFcpltedm1zfH1Ya3BFXTMjy6AVq4 4BaQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1725989948; x=1726594748; 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=4JYCYUJifJOf8IAr8uZJXdISd8++rwC9FrhK6nCyU7M=; b=S6BJCSxzNrq4ytYNsm7klRftSnpGQWaIcWiDyRKYylgvyX1ZMXCGFx6CTDGVsf4ugS ckjKH824U1+hSL5eAYUqmaZHkiPXqiG01BpkkgWXU5pOfms7zfPQul2k42wg/9hKIzkx xlBAZCVnkVv7Pug1OA65vOt1hw/gVji1/29tMTJsattCaBFcFxz4rv2dOt3vznf8vHtg lhs1Dk4heM5wa7bMrQr89eW7vTRBi+RXjRNTIqK/WmlVhWsoIx8CCjXoQeJFBYmBuE0r T5hSu23yNWI+Q6cDgIuLwSFjAwYSTqMNLVicbgkTBJXa2XkjE5YFJ6PTveemB0ffzTxo ZKjw== X-Gm-Message-State: AOJu0Ywl8Z/1kJiTrHyKojmrTw/NzoXCX0WEf9+n2vrk1fYz1ZKW/4Bg 5Rrwf0mU16PiXhCKCsdafqvUMTlR4bpkIpkqrUf+Xn8SpUinax2Q2NdKF3rvxn8= X-Received: by 2002:a17:907:7fa8:b0:a8d:128a:cc49 with SMTP id a640c23a62f3a-a8ffadc8c5amr121943666b.52.1725989948025; Tue, 10 Sep 2024 10:39:08 -0700 (PDT) Received: from draig.lan ([85.9.250.243]) by smtp.gmail.com with ESMTPSA id a640c23a62f3a-a8d2597ac96sm510004966b.73.2024.09.10.10.39.02 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 10 Sep 2024 10:39:04 -0700 (PDT) Received: from draig.lan (localhost [IPv6:::1]) by draig.lan (Postfix) with ESMTP id 1C1475FA0E; Tue, 10 Sep 2024 18:39:01 +0100 (BST) From: =?utf-8?q?Alex_Benn=C3=A9e?= To: qemu-devel@nongnu.org Cc: Thomas Huth , Zhao Liu , Peter Maydell , Paolo Bonzini , Marcel Apfelbaum , qemu-arm@nongnu.org, devel@lists.libvirt.org, Pierrick Bouvier , Alexandre Iooss , =?utf-8?q?Alex_Benn=C3=A9e?= , =?utf-8?q?Philippe_M?= =?utf-8?q?athieu-Daud=C3=A9?= , Jiaxun Yang , Beraldo Leal , Eduardo Habkost , Richard Henderson , Mahmoud Mandour , Yanan Wang , Wainer dos Santos Moschetta , Gustavo Romero Subject: [PATCH v2 07/10] gdbstub: Add support for MTE in system mode Date: Tue, 10 Sep 2024 18:38:57 +0100 Message-Id: <20240910173900.4154726-8-alex.bennee@linaro.org> X-Mailer: git-send-email 2.39.2 In-Reply-To: <20240910173900.4154726-1-alex.bennee@linaro.org> References: <20240910173900.4154726-1-alex.bennee@linaro.org> MIME-Version: 1.0 Received-SPF: pass client-ip=2a00:1450:4864:20::62c; envelope-from=alex.bennee@linaro.org; helo=mail-ej1-x62c.google.com X-Spam_score_int: -20 X-Spam_score: -2.1 X-Spam_bar: -- X-Spam_report: (-2.1 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=unavailable autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+patch=linaro.org@nongnu.org Sender: qemu-devel-bounces+patch=linaro.org@nongnu.org From: Gustavo Romero 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. Resolves: https://gitlab.com/qemu-project/qemu/-/issues/620 Signed-off-by: Gustavo Romero Reviewed-by: Richard Henderson Message-Id: <20240906143316.657436-3-gustavo.romero@linaro.org> [AJB: add #ifdef CONFIG_TCG guards] Signed-off-by: Alex Bennée --- v2 - while we enable system mode it is still TCG only so added guards to handle the --disable-tcg case (native KVM and Xen builds) --- target/arm/gdbstub64.c | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/target/arm/gdbstub64.c b/target/arm/gdbstub64.c index 85a19c14c7..1a4dbec567 100644 --- a/target/arm/gdbstub64.c +++ b/target/arm/gdbstub64.c @@ -430,7 +430,9 @@ int aarch64_gdb_set_tag_ctl_reg(CPUState *cs, uint8_t *buf, int reg) return 0; #endif } +#endif /* CONFIG_USER_ONLY */ +#ifdef CONFIG_TCG static void handle_q_memtag(GArray *params, void *user_ctx) { ARMCPU *cpu = ARM_CPU(user_ctx); @@ -600,13 +602,13 @@ static const GdbCmdParseEntry cmd_handler_table[NUM_CMDS] = { .need_cpu_context = true }, }; -#endif /* CONFIG_USER_ONLY */ +#endif /* CONFIG_TCG */ void aarch64_cpu_register_gdb_commands(ARMCPU *cpu, GString *qsupported, GPtrArray *qtable, GPtrArray *stable) { -#ifdef CONFIG_USER_ONLY /* MTE */ +#ifdef CONFIG_TCG if (cpu_isar_feature(aa64_mte, cpu)) { g_string_append(qsupported, ";memory-tagging+"); From patchwork Tue Sep 10 17:38:58 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: =?utf-8?q?Alex_Benn=C3=A9e?= X-Patchwork-Id: 827034 Delivered-To: patch@linaro.org Received: by 2002:adf:ab1c:0:b0:367:895a:4699 with SMTP id q28csp430690wrc; Tue, 10 Sep 2024 10:40:35 -0700 (PDT) X-Forwarded-Encrypted: i=2; AJvYcCUlbnJM3PtNO5Au9GPQEUg21FNkGpzFeKAqLAFHR6GGxZ4Q1b+AEJUPIKN5RRjR0F5DShNBDA==@linaro.org X-Google-Smtp-Source: AGHT+IHh2694FoZMq7qkYXVy+Ckx60zTeESjzPzrd4JFDG2bZ1fTS4rDzDWOQjdfFWzdwsu1k3kn X-Received: by 2002:a05:622a:1815:b0:458:4aec:2749 with SMTP id d75a77b69052e-4584aec2bcfmr29500871cf.57.1725990035692; Tue, 10 Sep 2024 10:40:35 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1725990035; cv=none; d=google.com; s=arc-20240605; b=TLS2VtTsYS9Wj9UzixrFZCf9s0TrHu8usYnUDkzeuu9n9OSvR3coCg8z1DRFsVXNpz cjr6w17VCNYnWF+rssPJRE0RR0nD1OCzWCSd2sCjbqYAmA/3CWr/lol6YHltuPpa5NAf svHL6PikPVdFENyAVt7PBFLLy9aERNEFCmAf6yn6b4YdFeOM4atKf3wtSjoEJaPAe6dQ V+qgFjS4/WKyjJO2mxnOAVMCSsrkODY1pisQXmV3zbi0JyF1Z5lKt0+kKxeLv7EThsC/ MJKXpwd0gdcqvrYldpge8owCKL+lr2ZDrXxtPDQDRSB5DCcLIety4ZyCj/ZxstJzkpAl YchA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20240605; 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=0gsP/ANf70RJH0KlgA0KWCypst2Oh4Yb8PQcZ6VG+qU=; fh=h773y6AOAE/ukr4mRlwaH0i0lfsEFb3Q85tR2q3kvZo=; b=cIzwrsJpS3RB6Q9TM+xnN1uuuI8YJqCcQ3hco39khoHLQTsHaWonkL1+cZQzXdK7Mz YO9IBm8yrnwmGMFmLHO2GRORLvSK1zjFDFoa5wIqd2pg0IPV1tCQh8xyZzHF+BKbxnG4 njMQ4hvhdxO/5MGPdnl/5YAzh+KDN2fInnLfvang6X77xxVQi1otpoJcTwWcrsO2cejm R8pjz+fPItGjgR+qRZAgt4rbBoNMbq0cTaEJ3rUUBLTjr/0OEBBg3VyQxPDrcvKyzqTM 9CJw3oMrdQIupTIRUQeiYim/7wavy6VccSvd/lQGwm/ZvcWawvcu0pHXJxVL+1Jb5QEC ZcrQ==; dara=google.com ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=CFUJVCMA; 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-45822e7ebb4si86186691cf.180.2024.09.10.10.40.35 for (version=TLS1_2 cipher=ECDHE-ECDSA-CHACHA20-POLY1305 bits=256/256); Tue, 10 Sep 2024 10:40:35 -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=CFUJVCMA; 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 1so4pk-0005EO-8Y; Tue, 10 Sep 2024 13:39:20 -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 1so4pa-0004mh-TV for qemu-devel@nongnu.org; Tue, 10 Sep 2024 13:39:11 -0400 Received: from mail-ej1-x629.google.com ([2a00:1450:4864:20::629]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1so4pY-0004Zt-8S for qemu-devel@nongnu.org; Tue, 10 Sep 2024 13:39:10 -0400 Received: by mail-ej1-x629.google.com with SMTP id a640c23a62f3a-a8a7b1c2f2bso167213166b.0 for ; Tue, 10 Sep 2024 10:39:07 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1725989946; x=1726594746; 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=0gsP/ANf70RJH0KlgA0KWCypst2Oh4Yb8PQcZ6VG+qU=; b=CFUJVCMA2vm7cJSDLpxCLFDM5b+5sHQYqPquJSiJBUBOqR6fy0Gbvf8mZtKc9u+YO5 LVMh5cPVGOcsdcO9pTnqc8uWVHMS5K/0I1io8hCXWJkPF/FmKCWThgZXzUs7lxg3tyxF h6LnaHTvTA5/ZHvkb84f0QLJbbEUTT8KWYNdsOuDIN+xhjA/4/oGKTMwtGjWG5r/e0tV MiGCVD28NJS04hYUMXurtRqK/H5RTfEPvhWyxfGh4IGAHWDF8DJQf/uK6aaSanZfBcW8 RA3fbKogTmVnS2WcrL/Lx/7GvX5MF4zefoSsbvzcl1dsaig3kwo2FJYp7/GRVYipYT9R kQAw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1725989946; x=1726594746; 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=0gsP/ANf70RJH0KlgA0KWCypst2Oh4Yb8PQcZ6VG+qU=; b=ZWCCPyfAK/3KKr/IoMSD/u1UZUQkq1q2goVy8w6yvD4oB0KOvQTQ3AGiNBRz7OBcbA j1fVg0hQqyUk22xQnBSABVL3gpNAzlSuz950I/wOjCs2xvPTM9b3bYHZ30TcKycOTLaz EBbRfdow+pTGlDDHlYLpuyAQINzMKLV2otC9t6g5y4TATusAS60mqY6GT9CS5W4AOAo/ SK3uPkDP9QAJvXUcUah6YcjHeWq/KXB6gKs535XB2BM62qCHmYWchEO2QOGxYuRb1vwJ yNLTE5dkhMEa3i2EiVleZ3UoVQanABaMUSA7nIKE7+XCqbRByaL78DYsvvR8lfZviBnz s7Uw== X-Gm-Message-State: AOJu0Yz8KHuxj4cU+JT3TysXS3i189usksYeqzUm7Fd4sYxaFrwoGgnZ Ulz0XRWh0TYs9PcCBRLWsg9YBhtSMFVo415AaSUwn1iYxc9TeYDwPptkjXavFEY= X-Received: by 2002:a17:907:2d13:b0:a86:aa57:57b8 with SMTP id a640c23a62f3a-a9004aba7c7mr29382466b.63.1725989946197; Tue, 10 Sep 2024 10:39:06 -0700 (PDT) Received: from draig.lan ([85.9.250.243]) by smtp.gmail.com with ESMTPSA id a640c23a62f3a-a8d25ce970csm505277266b.159.2024.09.10.10.39.02 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 10 Sep 2024 10:39:04 -0700 (PDT) Received: from draig.lan (localhost [IPv6:::1]) by draig.lan (Postfix) with ESMTP id 335A35FA11; Tue, 10 Sep 2024 18:39:01 +0100 (BST) From: =?utf-8?q?Alex_Benn=C3=A9e?= To: qemu-devel@nongnu.org Cc: Thomas Huth , Zhao Liu , Peter Maydell , Paolo Bonzini , Marcel Apfelbaum , qemu-arm@nongnu.org, devel@lists.libvirt.org, Pierrick Bouvier , Alexandre Iooss , =?utf-8?q?Alex_Benn=C3=A9e?= , =?utf-8?q?Philippe_M?= =?utf-8?q?athieu-Daud=C3=A9?= , Jiaxun Yang , Beraldo Leal , Eduardo Habkost , Richard Henderson , Mahmoud Mandour , Yanan Wang , Wainer dos Santos Moschetta , Gustavo Romero Subject: [PATCH v2 08/10] tests/guest-debug: Support passing arguments to the GDB test script Date: Tue, 10 Sep 2024 18:38:58 +0100 Message-Id: <20240910173900.4154726-9-alex.bennee@linaro.org> X-Mailer: git-send-email 2.39.2 In-Reply-To: <20240910173900.4154726-1-alex.bennee@linaro.org> References: <20240910173900.4154726-1-alex.bennee@linaro.org> MIME-Version: 1.0 Received-SPF: pass client-ip=2a00:1450:4864:20::629; envelope-from=alex.bennee@linaro.org; helo=mail-ej1-x629.google.com X-Spam_score_int: -20 X-Spam_score: -2.1 X-Spam_bar: -- X-Spam_report: (-2.1 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=unavailable autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+patch=linaro.org@nongnu.org Sender: qemu-devel-bounces+patch=linaro.org@nongnu.org From: Gustavo Romero 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 Message-Id: <20240906143316.657436-4-gustavo.romero@linaro.org> Signed-off-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 Tue Sep 10 17:38:59 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: =?utf-8?q?Alex_Benn=C3=A9e?= X-Patchwork-Id: 827040 Delivered-To: patch@linaro.org Received: by 2002:adf:ab1c:0:b0:367:895a:4699 with SMTP id q28csp431469wrc; Tue, 10 Sep 2024 10:42:24 -0700 (PDT) X-Forwarded-Encrypted: i=2; AJvYcCUGUq/ulaGdm8NZT7ZGODyL9tqFAEz3BZ9aWvucyu+F0pUXZdSV0VSOhcGfNWj8z/V/ZVtKpw==@linaro.org X-Google-Smtp-Source: AGHT+IHskRV6R4wUEdyAsapqj6ku20jxnt58dk+sZLUsRylBtK0WIKiUIqCQOJ0GbyNeR18AYHYl X-Received: by 2002:a05:6214:5546:b0:6c3:6409:cf14 with SMTP id 6a1803df08f44-6c55fa4eed5mr2320096d6.33.1725990144467; Tue, 10 Sep 2024 10:42:24 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1725990144; cv=none; d=google.com; s=arc-20240605; b=G5yAmGctfyt4f/FqvD4Hl0/aSTvR6IV/RUOur3oq5mqj/W6plMiL9Kh6JSwiKEBs3Z rm93p4ErdTBSz3qkGhqTvndv4rHkUGKQbtanlqgaPqGamdKgw20UZGNhemF3MmhGhmCf vUX+ViQ2HR7v7UXwIvD/SxMYJKkkDoQIvxe5+959/7WUyGG7h7ghvkl33kAPUlR9Uk5q 9HBjwQL6a/Orjq6YIcjmGe7O4g9U1a5Db4dtezmReQJ2Xv0I8SoLnTHi+rrL3Hyr+LRB iM9i0nbNp62DDJR1cB5P0iDWP6J6sBlaHi/3mb18xxnX+zT3myTh3bemdi+E92aJ/7Vo 7MPw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20240605; 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=Y9b0lTkZojj9hYO/C00YAyDV7juvCe44sJPqhBOockE=; fh=h773y6AOAE/ukr4mRlwaH0i0lfsEFb3Q85tR2q3kvZo=; b=i0VkJL7l3ShrNy3lSyQTjLnOnApViWyt4mYhmp47TQTQ92LivMVJ/Jujr+UgchATZ3 uFt7FebciWHSMtijeTzKpn0pKkeY0kuYcG7Zmz9wI6ei3cRg1A2Tho1ZEK6oW3AQpye8 oWk+EpYFPwMrcKw4Fq7qkWXvtF5nhYsGb8bnwYpMBNj44NuOn/DxEXIihsP/biJsa075 y8PvrMOt7BjjhuLdOxylT3KV46NWKKkByaoqlT9k8TBmOC+1Vb3/0Ez06IRn1whv55fm NsvAEQRcUO6geNneS1oM+1n+IS3KxHe5Y7GsOH1Ztw7GfCYwRfQ+TfP46pfEt6qQsJ0k as9g==; dara=google.com ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=niRGpHpH; 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 6a1803df08f44-6c5347bdd4bsi82731736d6.477.2024.09.10.10.42.24 for (version=TLS1_2 cipher=ECDHE-ECDSA-CHACHA20-POLY1305 bits=256/256); Tue, 10 Sep 2024 10:42:24 -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=niRGpHpH; 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 1so4py-0006Ao-7Z; Tue, 10 Sep 2024 13:39:34 -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 1so4pd-0004t5-I9 for qemu-devel@nongnu.org; Tue, 10 Sep 2024 13:39:13 -0400 Received: from mail-ed1-x52e.google.com ([2a00:1450:4864:20::52e]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1so4pc-0004be-0e for qemu-devel@nongnu.org; Tue, 10 Sep 2024 13:39:13 -0400 Received: by mail-ed1-x52e.google.com with SMTP id 4fb4d7f45d1cf-5c26852af8fso7610781a12.2 for ; Tue, 10 Sep 2024 10:39:11 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1725989950; x=1726594750; 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=Y9b0lTkZojj9hYO/C00YAyDV7juvCe44sJPqhBOockE=; b=niRGpHpH5EsrPY1FiN7NDMoDWph4ZgorKU0nMTyg9NN/qfDafzZT6mA5ybPux0Xkdd aZqK3eE/xsPpeNz800wb7XRU+yAcn53j7J7K74xBp0OEJ3DREZdraSUYitJlS3q0Ld5W cfkapTyRWJ6lLxFAfZMBrdVqb0QFJXcbWt7DcQ/Ys4yJ4IhEwjYCuiawiRupz7WdNiM7 VRDYcsYzLOVqyxAmihnR1duT0HT9AhZSmowO6ROrA9b9N3jcbk9y3Wd/rgdsl3OtUenp smA6IRkQhBaX0uvrsz7dIYA1O5OKB2zDuHixCSs2O0nr1V59pS4uw1j+EnTObGcGDvQJ Mnpw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1725989950; x=1726594750; 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=Y9b0lTkZojj9hYO/C00YAyDV7juvCe44sJPqhBOockE=; b=qM60yoVFk3y8qrvq8SlyJRCT55yohan+WEQitve+87XW8ac/Yy3kTJMf1AW27FF4DE huQcwZp60PmgMZlWaVl0ogx4YqLbinApXd3NWy3zB0Lv3qTMs1yfRc3MBM6gPPHsizMO Bnxtkfdsu8UtfumrnupB0R8CjXf9dmK1wTmFIF4I5my7ZYGBGX4+905qr4tX+GOnHObi 5/30BCX4PtX372YQWdjhcscSquzGdoOtIVEbr62GrkUb4TeI9BqViSl078jwMPdyjt+S W+U90fCsAxf56vGsDaf1LU3yNA7ZhtafHp7NSdTAJHIyAcP8SslCfGjcW9TXWcBtqaFM IKYg== X-Gm-Message-State: AOJu0YxEWHnF8PXqc94LrF8Tn4Cl7cazGIvBz6azkl0Ofo468LHVWRPf HH++aTqz1zrEl7rgHicxkKsczNUkt8yZCJKEdpaLqdvCD7Pot1Tr+sSSyS4nc0M= X-Received: by 2002:a05:6402:3506:b0:5c2:60cd:b814 with SMTP id 4fb4d7f45d1cf-5c3e9630d6emr9848491a12.12.1725989950314; Tue, 10 Sep 2024 10:39:10 -0700 (PDT) Received: from draig.lan ([85.9.250.243]) by smtp.gmail.com with ESMTPSA id 4fb4d7f45d1cf-5c3ebd76f96sm4438739a12.74.2024.09.10.10.39.03 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 10 Sep 2024 10:39:08 -0700 (PDT) Received: from draig.lan (localhost [IPv6:::1]) by draig.lan (Postfix) with ESMTP id 4B5045FA14; Tue, 10 Sep 2024 18:39:01 +0100 (BST) From: =?utf-8?q?Alex_Benn=C3=A9e?= To: qemu-devel@nongnu.org Cc: Thomas Huth , Zhao Liu , Peter Maydell , Paolo Bonzini , Marcel Apfelbaum , qemu-arm@nongnu.org, devel@lists.libvirt.org, Pierrick Bouvier , Alexandre Iooss , =?utf-8?q?Alex_Benn=C3=A9e?= , =?utf-8?q?Philippe_M?= =?utf-8?q?athieu-Daud=C3=A9?= , Jiaxun Yang , Beraldo Leal , Eduardo Habkost , Richard Henderson , Mahmoud Mandour , Yanan Wang , Wainer dos Santos Moschetta , Gustavo Romero Subject: [PATCH v2 09/10] tests/tcg/aarch64: Improve linker script organization Date: Tue, 10 Sep 2024 18:38:59 +0100 Message-Id: <20240910173900.4154726-10-alex.bennee@linaro.org> X-Mailer: git-send-email 2.39.2 In-Reply-To: <20240910173900.4154726-1-alex.bennee@linaro.org> References: <20240910173900.4154726-1-alex.bennee@linaro.org> MIME-Version: 1.0 Received-SPF: pass client-ip=2a00:1450:4864:20::52e; envelope-from=alex.bennee@linaro.org; helo=mail-ed1-x52e.google.com X-Spam_score_int: -20 X-Spam_score: -2.1 X-Spam_bar: -- X-Spam_report: (-2.1 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=unavailable autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+patch=linaro.org@nongnu.org Sender: qemu-devel-bounces+patch=linaro.org@nongnu.org From: Gustavo Romero Improve kernel.ld linker script organization by using MEMORY command. Signed-off-by: Richard Henderson Signed-off-by: Gustavo Romero Message-Id: <20240906143316.657436-5-gustavo.romero@linaro.org> Signed-off-by: Alex Bennée --- tests/tcg/aarch64/system/kernel.ld | 24 ++++++++++++------------ 1 file changed, 12 insertions(+), 12 deletions(-) diff --git a/tests/tcg/aarch64/system/kernel.ld b/tests/tcg/aarch64/system/kernel.ld index 7b3a76dcbf..5f39258d32 100644 --- a/tests/tcg/aarch64/system/kernel.ld +++ b/tests/tcg/aarch64/system/kernel.ld @@ -1,23 +1,23 @@ ENTRY(__start) -SECTIONS -{ - /* virt machine, RAM starts at 1gb */ - . = (1 << 30); +MEMORY { + /* On virt machine RAM starts at 1 GiB. */ + + /* Align text and rodata to the 1st 2 MiB chunk. */ + TXT (rx) : ORIGIN = 1 << 30, LENGTH = 2M + /* Align r/w data to the 2nd 2 MiB chunk. */ + DAT (rw) : ORIGIN = (1 << 30) + 2M, LENGTH = 2M +} + +SECTIONS { .text : { *(.text) - } - .rodata : { *(.rodata) - } - /* align r/w section to next 2mb */ - . = ALIGN(1 << 21); + } >TXT .data : { *(.data) - } - .bss : { *(.bss) - } + } >DAT /DISCARD/ : { *(.ARM.attributes) } From patchwork Tue Sep 10 17:39:00 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: =?utf-8?q?Alex_Benn=C3=A9e?= X-Patchwork-Id: 827041 Delivered-To: patch@linaro.org Received: by 2002:adf:ab1c:0:b0:367:895a:4699 with SMTP id q28csp431493wrc; Tue, 10 Sep 2024 10:42:27 -0700 (PDT) X-Forwarded-Encrypted: i=2; AJvYcCUIZW08xxS+4fj8jzCHA9rXkI4s1esRW0d0lp+EC8zg8rxOOexYq9O+BdKuXLApp76o6Ehtkg==@linaro.org X-Google-Smtp-Source: AGHT+IE0zR0c2lazszGQzgtOq6oieCLlzs2QjZW1nRJpF3Me3BtW9BelhRbunUEGdDZ1MmYmzqRQ X-Received: by 2002:a05:620a:1a26:b0:79f:e94:4436 with SMTP id af79cd13be357-7a9bf97dcefmr735338785a.16.1725990147523; Tue, 10 Sep 2024 10:42:27 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1725990147; cv=none; d=google.com; s=arc-20240605; b=QtcsKxEbgXMLs+ApMkZqm/E86EpLMY6NFEnBqZ/dILuoPdpoiB+/ALmUqSCZJv4qJD 1Sz8WMvEregopJ6nzsbhrgJ4X/KIINR5s13X65z6H/yg4mc9MjnzaYkElepAJQNmG85y /y0tDWTtvdU+jWe4Kr18y4Z7ikrwz5A6+d9OyNTRZP/WqYOqzGWdahQ/kI8BW3BxWkcX u7zV5goCjB8J7jT8Hs7gHqHrsBvHvLBGXqm48WMeKrii2frx5R1D1iuTR4vSPJMgSi1V ue0TP3FFPt+BF6+AcjH4TSOWiT4qVpWa5s+QHp/p0qg3koXPaBPKwScDKoAX8e09nn2U 0aEw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20240605; 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=HoFAgf8Kp5KNK0KvKfU77RN/Ll2Ls2Lkh4OwDrxuJmk=; fh=h773y6AOAE/ukr4mRlwaH0i0lfsEFb3Q85tR2q3kvZo=; b=Is+jclB09RiuKOC1QI+RKyI7vnOdscKf9dJO1VX9DltRFLx30eo5yV7w1QWeFI6Rbk CeEZA4R38bw5x4HDdHA0B/N9XkTL6ApQwDrUf4n2dmKIZyanc6CcEE5B3xUqu/zWXcEr a7l4h1zQMqHbkTA3gzsatG6A6gXIvz5lwvQ/wfrhPT9N90hrryNoNt5SlSyKFXiA/hBe b1BGcduPP3XgsFsJmW068v5VED4BFCbmOftZvm4P+ycoSYQ+n/vsOxcFZcYCM8N6K9uG dDtuQIRkJYjixzAbz9AAYNPo7Ei3/M3I/Uq6ycA4mXwMk1zNRIVlKUT8nbw763o0XRg9 CL7g==; dara=google.com ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=tHh3nFZQ; 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-7a9a7a7b167si831687885a.699.2024.09.10.10.42.27 for (version=TLS1_2 cipher=ECDHE-ECDSA-CHACHA20-POLY1305 bits=256/256); Tue, 10 Sep 2024 10:42:27 -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=tHh3nFZQ; 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 1so4pr-0005fQ-5F; Tue, 10 Sep 2024 13:39:27 -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 1so4pg-00056A-Ms for qemu-devel@nongnu.org; Tue, 10 Sep 2024 13:39:20 -0400 Received: from mail-lf1-x135.google.com ([2a00:1450:4864:20::135]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1so4pa-0004b9-LU for qemu-devel@nongnu.org; Tue, 10 Sep 2024 13:39:16 -0400 Received: by mail-lf1-x135.google.com with SMTP id 2adb3069b0e04-53661ac5ba1so1209469e87.2 for ; Tue, 10 Sep 2024 10:39:10 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1725989949; x=1726594749; 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=HoFAgf8Kp5KNK0KvKfU77RN/Ll2Ls2Lkh4OwDrxuJmk=; b=tHh3nFZQ79BGYzaEBrlDfL5f0bDGIv37Dz68dcn/4HS+UUk7b6ND3DDiUaDNFWxc8/ 4OsqgUn2OaUSD0+GFjyHv049fRyOkOqFKa2tS7CIchqjRjK3ImKPG1yGVByN/THM5/KO iAM4jdLi5VcZ9IHY1UECEQ0U0RaBLap+hfPyI48phlq61uXlRLOhTcubZvpA2Mx0J8dl fHjcDUXnGrQpW06zKZbfXRwhpg714POS6b9DAkJYnZ4YhxA5GpETi9Vcgd7X7+m4PzPI 1LZ/iRkv5/VtNQegQv7ypcmaTwRnG5G8ydwe9WquXL74dFVswbSeciVmoszzcP1hah/8 7K5Q== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1725989949; x=1726594749; 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=HoFAgf8Kp5KNK0KvKfU77RN/Ll2Ls2Lkh4OwDrxuJmk=; b=cY+Dv1sy7ozDJHE+lSa8dU4EDc/1Hrd9R1zsZg3/yVle7ehoSJDgEakuPNJ916DHAS xB1TlRVIq5XH899tvAth7jfwtyqZxll7Ys7Y/9Dki70XtH6pLva+bTVEtiyLvxQ8ej6t fCjVThxN1BM4vho6cx+WMloni9yjYRFRLolHvlC6cEcEBuH2XXLmuk1Qb/p9HaHFvlsD cULmhX0dY2hAfgIC/s8/ZAW9P+iwaBrAvmSSfKJ4w83BClHdycIw6wOU8ueU0O2QLfRF 59/FVsfrhEP5ZrIuZXjQzdKyVt6/8ZGqYveWm6D3xBLaXNHe2im9+kOY3wOxpJzczbUG Ecxw== X-Gm-Message-State: AOJu0YzHFd73xfWBzcj3LF1e7OdYJM96VM8TbZ9/0767g3D27jKVEXS/ 7tJ/IZMm18f1TirHDiLlk207XeZwaIu4eDfCgxptpFHruIUPagC4kPh5xDqvywM= X-Received: by 2002:a05:6512:12ca:b0:536:5530:af46 with SMTP id 2adb3069b0e04-53673ca14f4mr191544e87.52.1725989948456; Tue, 10 Sep 2024 10:39:08 -0700 (PDT) Received: from draig.lan ([85.9.250.243]) by smtp.gmail.com with ESMTPSA id a640c23a62f3a-a8d25c73bc1sm509364866b.136.2024.09.10.10.39.03 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 10 Sep 2024 10:39:04 -0700 (PDT) Received: from draig.lan (localhost [IPv6:::1]) by draig.lan (Postfix) with ESMTP id 6A9185FA18; Tue, 10 Sep 2024 18:39:01 +0100 (BST) From: =?utf-8?q?Alex_Benn=C3=A9e?= To: qemu-devel@nongnu.org Cc: Thomas Huth , Zhao Liu , Peter Maydell , Paolo Bonzini , Marcel Apfelbaum , qemu-arm@nongnu.org, devel@lists.libvirt.org, Pierrick Bouvier , Alexandre Iooss , =?utf-8?q?Alex_Benn=C3=A9e?= , =?utf-8?q?Philippe_M?= =?utf-8?q?athieu-Daud=C3=A9?= , Jiaxun Yang , Beraldo Leal , Eduardo Habkost , Richard Henderson , Mahmoud Mandour , Yanan Wang , Wainer dos Santos Moschetta , Gustavo Romero Subject: [PATCH v2 10/10] tests/tcg/aarch64: Extend MTE gdbstub tests to system mode Date: Tue, 10 Sep 2024 18:39:00 +0100 Message-Id: <20240910173900.4154726-11-alex.bennee@linaro.org> X-Mailer: git-send-email 2.39.2 In-Reply-To: <20240910173900.4154726-1-alex.bennee@linaro.org> References: <20240910173900.4154726-1-alex.bennee@linaro.org> MIME-Version: 1.0 Received-SPF: pass client-ip=2a00:1450:4864:20::135; envelope-from=alex.bennee@linaro.org; helo=mail-lf1-x135.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, T_SPF_TEMPERROR=0.01 autolearn=unavailable autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+patch=linaro.org@nongnu.org Sender: qemu-devel-bounces+patch=linaro.org@nongnu.org From: Gustavo Romero 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 Message-Id: <20240906143316.657436-6-gustavo.romero@linaro.org> [AJB: fix stray _] Signed-off-by: Alex Bennée --- v2 fixed stray underline causing tests to be skipped --- 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 | 9 ++ tests/tcg/aarch64/system/mte.S | 109 ++++++++++++++++++++++ 7 files changed, 229 insertions(+), 28 deletions(-) create mode 100644 tests/tcg/aarch64/system/mte.S diff --git a/configure b/configure index 39a284ddfe..7f6eb6b331 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..d08d9b01de 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 5f39258d32..aef043e31d 100644 --- a/tests/tcg/aarch64/system/kernel.ld +++ b/tests/tcg/aarch64/system/kernel.ld @@ -7,6 +7,8 @@ MEMORY { TXT (rx) : ORIGIN = 1 << 30, LENGTH = 2M /* Align r/w data to the 2nd 2 MiB chunk. */ DAT (rw) : ORIGIN = (1 << 30) + 2M, LENGTH = 2M + /* Align the MTE-enabled page to the 3rd 2 MiB chunk. */ + TAG (rw) : ORIGIN = (1 << 30) + 4M, LENGTH = 2M } SECTIONS { @@ -18,6 +20,13 @@ SECTIONS { *(.data) *(.bss) } >DAT + .tag : { + /* + * Symbol 'mte_page' 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 = .; + } >TAG /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